CSES - Datatähti 2018 loppu - Results
Submission details
Task:Merkkijono
Sender:ArktinenKarpalo
Submission time:2018-01-18 15:01:37 +0200
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.03 sdetails
#3ACCEPTED0.04 sdetails
#4ACCEPTED0.06 sdetails
#5ACCEPTED0.03 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:14:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=1; i<s.size(); i++) {
                 ^
input/code.cpp:12:8: warning: variable 'bt' set but not used [-Wunused-but-set-variable]
   bool bt = true;
        ^
input/code.cpp:23:8: warning: unused variable 'aa' [-Wunused-variable]
   bool aa = false;
        ^

Code

#include <bits/stdc++.h>
#define ll long long

using namespace std;

string s;
vector<int> ans;

int main() {
	cin >> s;
	while(true) {
		bool bt = true;
		bool ccc = true;
		for(int i=1; i<s.size(); i++) {
			if(s[i]<s[i-1]) {
				ccc = false;
				break;
			}
		}
		if(s[0]=='A'&&ccc) {
			break;
		}
		bool aa = false;
		for(int i=s.size()-2; i>=0; i--) {
			if(s[i]=='A')
				break;
			if(s[i]>s[i+1]&&s[i+1]!='A'&&s[i]!='A') {
				bt = false;
				char cha = s[i];
				while(s[0]!=cha) {
					s = s.substr(s.size()-1, 1)+s;
					s.pop_back();
					ans.push_back(0);
				}
				char a = s[0];
				s[0] = s[1];
				s[1] = a;
				ans.push_back(1);
				break;
			}
		}
			if(s[0]!='A') {	
					s = s.substr(s.size()-1, 1)+s;
					s.pop_back();
					ans.push_back(0);
			}
	}
	cout << ans.size() << "\n";
	for(auto u:ans)
		if(u)
			cout <<"SWAP\n";
		else
			cout <<"MOVE\n";

}

Test details

Test 1

Verdict: ACCEPTED

input
ABCDEFGHIJKLMNOPQRSTUVWXYZ

correct output
0

user output
0

Test 2

Verdict: ACCEPTED

input
ZYXWVUTSRQPONMLKJIHGFEDCBA

correct output
923
MOVE
MOVE
SWAP
MOVE
...

user output
1549
MOVE
MOVE
MOVE
SWAP
...

Test 3

Verdict: ACCEPTED

input
RPJMFWBHYQOTXUAENLDGZISCVK

correct output
611
SWAP
MOVE
MOVE
SWAP
...

user output
853
MOVE
MOVE
SWAP
MOVE
...

Test 4

Verdict: ACCEPTED

input
GWJSPBHANMXYFLKIDORVUCEZQT

correct output
659
MOVE
SWAP
MOVE
SWAP
...

user output
1221
MOVE
MOVE
MOVE
SWAP
...

Test 5

Verdict: ACCEPTED

input
BJYNFLKEIUCZMQHRAXOGWPSDTV

correct output
624
MOVE
SWAP
MOVE
SWAP
...

user output
928
MOVE
MOVE
MOVE
MOVE
...