Task: | Merkkijono |
Sender: | paavoee |
Submission time: | 2018-01-18 14:53:14 +0200 |
Language: | C++ |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.05 s | details |
#2 | ACCEPTED | 0.06 s | details |
#3 | ACCEPTED | 0.06 s | details |
#4 | ACCEPTED | 0.05 s | details |
#5 | ACCEPTED | 0.04 s | details |
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 ... |