| Task: | Merkkijono |
| Sender: | mika |
| Submission time: | 2018-01-18 14:23:51 +0200 |
| Language: | C++ |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.05 s | details |
| #2 | WRONG ANSWER | 0.03 s | details |
| #3 | TIME LIMIT EXCEEDED | -- | details |
| #4 | TIME LIMIT EXCEEDED | -- | details |
| #5 | TIME LIMIT EXCEEDED | -- | 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: WRONG ANSWER
| input |
|---|
| ZYXWVUTSRQPONMLKJIHGFEDCBA |
| correct output |
|---|
| 923 MOVE MOVE SWAP MOVE ... |
| user output |
|---|
| AZYXWVUTSRQPONMLKJIHGFEDCB 8 MOVE MOVE SWAP ... |
Test 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| RPJMFWBHYQOTXUAENLDGZISCVK |
| correct output |
|---|
| 611 SWAP MOVE MOVE SWAP ... |
| user output |
|---|
| (empty) |
Test 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| GWJSPBHANMXYFLKIDORVUCEZQT |
| correct output |
|---|
| 659 MOVE SWAP MOVE SWAP ... |
| user output |
|---|
| (empty) |
Test 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| BJYNFLKEIUCZMQHRAXOGWPSDTV |
| correct output |
|---|
| 624 MOVE SWAP MOVE SWAP ... |
| user output |
|---|
| (empty) |
