CSES - Datatähti 2018 loppu - Results
Submission details
Task:Merkkijono
Sender:mika
Submission time:2018-01-18 14:23:51 +0200
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#20.03 sdetails
#3--details
#4--details
#5--details

Compiler report

input/code.cpp: In function 'int score(std::string)':
input/code.cpp:32:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < s.size(); i++) {
                    ^
input/code.cpp: In function 'int main()':
input/code.cpp:72:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ops.size(); i++) {
                    ^

Code

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <unordered_set>
using namespace std;
string M = "MOVE";
string S = "SWAP";
vector<string> ops;
string s;
void swap() {
char t = s[1];
s[1] = s[0];
s[0] = t;
ops.push_back(S);
}
void move() {
char t = s[s.size() - 1];
s = t + s.substr(0, s.size() - 1);
ops.push_back(M);
}
int score(string s) {
int sc = 0;
for (int i = 0; i < s.size(); i++) {
if ((int)s[i] != 65 + i) sc++;
}
return sc;
}
void haku() {
int sc = score(s);
//cout << "init score: " << sc << endl;
if (sc <= 0)
return;
string bak = s;
//cout << "before: " << s << endl;
move();
//cout << "moved: " << s << endl;
if (score(s) <= sc)
haku();
else
s = bak;
//cout << "before: " << s << endl;
swap();
//cout << "swapped: " << s << endl;
if (score(s) <= sc)
haku();
else
s = bak;
}
int main() {
cin >> s;
haku();
cout << s << endl;
cout << ops.size() << endl;
for (int i = 0; i < ops.size(); i++) {
cout << ops[i] << endl;
}
return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
ABCDEFGHIJKLMNOPQRSTUVWXYZ

correct output
0

user output
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0

Test 2

Verdict:

input
ZYXWVUTSRQPONMLKJIHGFEDCBA

correct output
923
MOVE
MOVE
SWAP
MOVE
...

user output
AZYXWVUTSRQPONMLKJIHGFEDCB
8
MOVE
MOVE
SWAP
...

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)