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

Code

/*
 * merkkijono.cpp
 *
 *  Created on: Jan 18, 2018
 *      Author: guest410
 */

#include <iostream>
#include <vector>

using namespace std;

long int num_inst = 0;
vector<bool> insts;

inline void MOVE(string& s) {
	insts.push_back(true);
	s.insert(s.begin(), s.back());
	s.pop_back();
	num_inst++;
}

inline void SWAP(string& s) {
	insts.push_back(false);
	char tmp = s[0];
	s[0] = s[1];
	s[1] = tmp;
	num_inst++;
}

int main() {
	string s;
	cin >> s;
	for (int times = 25; times > 0; times--) {
		bool found = false;
		int i = 2;
		for (int n = 25; n > 0; n--, i++) {
			if (s[n-1] > s[n]) {
				for (int j = 0; j < i; j++) MOVE(s);
				SWAP(s);
				found = true;
				break;
			}
		}
		if (!found) break;
		for (int k = 0; k < times - i + 1; k++) {
			MOVE(s);
			if (s[0] > s[1]) SWAP(s);
		}
		for (int j = 0; j < 25 - times; j++) MOVE(s);
	}
	cout << num_inst << '\n';
	for (auto it = insts.begin(); it != insts.end(); it++) {
		cout << (*it ? "MOVE\n" : "SWAP\n");
	}
	return 0;
}

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
975
MOVE
MOVE
SWAP
MOVE
...

Test 3

Verdict: ACCEPTED

input
RPJMFWBHYQOTXUAENLDGZISCVK

correct output
611
SWAP
MOVE
MOVE
SWAP
...

user output
613
MOVE
MOVE
SWAP
MOVE
...

Test 4

Verdict: ACCEPTED

input
GWJSPBHANMXYFLKIDORVUCEZQT

correct output
659
MOVE
SWAP
MOVE
SWAP
...

user output
689
MOVE
MOVE
MOVE
SWAP
...

Test 5

Verdict: ACCEPTED

input
BJYNFLKEIUCZMQHRAXOGWPSDTV

correct output
624
MOVE
SWAP
MOVE
SWAP
...

user output
704
MOVE
MOVE
MOVE
MOVE
...