Task: | Merkkijono |
Sender: | Yytsi |
Submission time: | 2018-01-18 13:52:53 +0200 |
Language: | C++ |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.05 s | details |
#2 | TIME LIMIT EXCEEDED | -- | details |
#3 | TIME LIMIT EXCEEDED | -- | details |
#4 | RUNTIME ERROR | 0.93 s | details |
#5 | TIME LIMIT EXCEEDED | -- | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:36:27: warning: unused variable 'popped' [-Wunused-variable] string s; cin >> s; bool popped = false; ^
Code
#include <iostream> #include <string> #include <vector> using namespace std; vector<int> lst; vector<int> oper; int k = 0; bool popped = false; bool sorted() { for (int i = 0; i < (int)lst.size()-1; i++) { if (lst[i] > lst[i + 1]) return false; } return true; } int ab(int a, int b) { return (a<b)?(b-a):(a-b); } void sw() { int f = lst[1]; lst[1] = lst[0]; lst[0] = f; oper.push_back(0); k++; } void mov() { int last = lst[25]; lst.pop_back(); lst.insert(lst.begin(), last); oper.push_back(1); k++; } int main() { string s; cin >> s; bool popped = false; for (int i = 0; i < (int)s.size(); i++) { char c = s[i]; lst.push_back((int)c - 65); } while (!sorted()) { int diff = ab(lst[0],lst[1]); if (lst[0] > lst[1] && diff == 1) { sw(); } else if (diff != 1) { // We want arr[0] to have arr[0] - 1 before it. mov(); while (lst[0] != (lst[1] - 1)) { sw(); mov(); } if (!sorted()) mov(); } else { mov(); } } cout << k << "\n"; for (int i = 0; i < (int)oper.size(); i++) { if (lst[i] == 0) cout << "SWAP\n"; else cout << "MOVE\n"; } return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
ABCDEFGHIJKLMNOPQRSTUVWXYZ |
correct output |
---|
0 |
user output |
---|
0 |
Test 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
ZYXWVUTSRQPONMLKJIHGFEDCBA |
correct output |
---|
923 MOVE MOVE SWAP MOVE ... |
user output |
---|
(empty) |
Test 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
RPJMFWBHYQOTXUAENLDGZISCVK |
correct output |
---|
611 SWAP MOVE MOVE SWAP ... |
user output |
---|
(empty) |
Test 4
Verdict: RUNTIME ERROR
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) |