Task: | Merkkijono |
Sender: | ollpu |
Submission time: | 2018-01-18 12:45:54 +0200 |
Language: | C++ |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 100 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.03 s | details |
#2 | ACCEPTED | 0.05 s | details |
#3 | ACCEPTED | 0.04 s | details |
#4 | ACCEPTED | 0.05 s | details |
#5 | ACCEPTED | 0.06 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:19:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i = 0; i < s.size(); ++i) { ^ input/code.cpp:33:12: warning: 'mni' may be used uninitialized in this function [-Wmaybe-uninitialized] while (o != mni) { ^
Code
#include <iostream> #include <vector> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int n = s.size(); vector<int> r; int o = 0; char mnc = 'a'; int mni; for (int i = 0; i < n; ++i) { if (s[i] < mnc) mnc = s[i], mni = i; } while (true) { bool f = 0; for (int i = 0; i < s.size(); ++i) { if ((n-i+o+1)%n == mni) continue; if (s[(n-i+o)%n] > s[(n-i+o+1)%n]) { f = 1; o += n-i; o %= n; for (int j = 0; j < i; ++j) r.push_back(0); } } if (f) { r.push_back(1); swap(s[o], s[(o+1)%n]); } else break; } while (o != mni) { r.push_back(0); o += n-1; o %= n; } cout << r.size() << endl; for (int rr : r) { if (rr) cout << "SWAP\n"; else cout << "MOVE\n"; } }
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 |
---|
36935 MOVE MOVE MOVE MOVE ... |
Test 3
Verdict: ACCEPTED
input |
---|
RPJMFWBHYQOTXUAENLDGZISCVK |
correct output |
---|
611 SWAP MOVE MOVE SWAP ... |
user output |
---|
11253 MOVE MOVE MOVE MOVE ... |
Test 4
Verdict: ACCEPTED
input |
---|
GWJSPBHANMXYFLKIDORVUCEZQT |
correct output |
---|
659 MOVE SWAP MOVE SWAP ... |
user output |
---|
17055 MOVE MOVE MOVE MOVE ... |
Test 5
Verdict: ACCEPTED
input |
---|
BJYNFLKEIUCZMQHRAXOGWPSDTV |
correct output |
---|
624 MOVE SWAP MOVE SWAP ... |
user output |
---|
11432 MOVE MOVE MOVE MOVE ... |