CSES - Datatähti 2018 loppu - Results
Submission details
Task:Merkkijono
Sender:valokoodari
Submission time:2018-01-18 15:25:28 +0200
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#20.04 sdetails
#30.06 sdetails
#40.05 sdetails
#50.05 sdetails

Code

#include <bits/stdc++.h>
using namespace std;

vector<char> al = {	'A','B','C','D','E','F','G',
			'H','I','J','K','L','M','N',
			'O','P','Q','R','S','T','U',
			'V','W','X','Y','Z'};

int main() {
	string n;
	cin >> n;

	vector<int> a(al.size());
	for (unsigned int i = 0; i < al.size(); i++)
		for (unsigned int j = 0; j < al.size(); j++)
			if (n[i] == al[j]) {
				a[i] = j;
				break;
			}

	vector<int> b = a;
	sort(b.begin(), b.end());
	
	int k = 0;
	int s;
	vector<int> m;
	while(b != a) {
		k++;
		if (a[0] > a[1]) {
			m.push_back(0);
			s = a[1];
			a.erase(a.begin() + 1);
			a.insert(a.begin(), s);
		} else {
			m.push_back(1);
			a.insert(a.begin(), a.back());
			a.pop_back();
		}
		if (k > 100000)
			return 1;
	}

/* Debug
	for (unsigned int i = 0; i < a.size(); i++)
		cout << a[i] << endl;
*/
	// Output
	cout << k << endl;
	for (unsigned int i = 0; i < m.size(); i++)
		cout << ((m[i])?"MOVE":"SWAP") << endl;
	return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
ABCDEFGHIJKLMNOPQRSTUVWXYZ

correct output
0

user output
0

Test 2

Verdict:

input
ZYXWVUTSRQPONMLKJIHGFEDCBA

correct output
923
MOVE
MOVE
SWAP
MOVE
...

user output
(empty)

Test 3

Verdict:

input
RPJMFWBHYQOTXUAENLDGZISCVK

correct output
611
SWAP
MOVE
MOVE
SWAP
...

user output
(empty)

Test 4

Verdict:

input
GWJSPBHANMXYFLKIDORVUCEZQT

correct output
659
MOVE
SWAP
MOVE
SWAP
...

user output
(empty)

Test 5

Verdict:

input
BJYNFLKEIUCZMQHRAXOGWPSDTV

correct output
624
MOVE
SWAP
MOVE
SWAP
...

user output
(empty)