# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29575 | 2017-07-20T07:17:54 Z | 서규호(#1242) | Shift (POI11_prz) | C++14 | 1000 ms | 26700 KB |
#include <bits/stdc++.h> #include <unistd.h> #define pii pair<int,int> #define pll pair<lld,lld> #define pb push_back #define next nextt #define left leftt #define right rightt #define lld long long #define Inf 1000000000 #define Mod 1000000007 #define Linf 1000000000000000000LL #define get gett using namespace std; int N; int a[2002]; deque<int> q; vector<int> print; int process(){ int t1,t2,t3; t1 = q.front(); q.pop_front(); t2 = q.front(); q.pop_front(); t3 = q.front(); q.pop_front(); if((t1 < t2 && t1 < t3) || (t2 < t1 && t1 < t3) || (t3 < t2 && t2 < t1)){ q.push_front(t3); q.push_front(t2); q.push_front(t1); return 0; }else if(t2 < t1 && t2 < t3){ q.push_front(t1); q.push_front(t3); q.push_front(t2); return 2; }else{ q.push_front(t2); q.push_front(t1); q.push_front(t3); return 1; } } int main(){ //freopen("input.txt","r",stdin); scanf("%d",&N); for(int i=1; i<=N; i++){ scanf("%d",&a[i]); q.pb(a[i]); } if(N == 2 && a[1] == 2) print.pb(1); if(N > 2){ int get; while(print.size()+3 <= N*N){ bool update = false; for(int i=0; i<N; i++){ get = process(); if(get != 0){ if(i > 0) print.pb(i); print.pb(-get); update = true; break; } get = q.back(); q.pop_back(); q.push_front(get); } if(!update) break; } } for(int i=1; i<=N; i++){ a[i] = q.front(); q.pop_front(); } int tmp = min_element(a+1,a+N+1)-a; if(tmp != 1) print.pb(N+1-tmp); rotate(a+1,min_element(a+1,a+N+1),a+N+1); for(int i=1; i<=N; i++){ if(i != a[i]){ puts("NIE DA SIE"); return 0; } } printf("%d\n",print.size()); for(auto &i : print){ if(i > 0) printf("%da ",i); else printf("%db ",-i); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2032 KB | Output is correct |
2 | Incorrect | 0 ms | 2032 KB | Expected integer, but "NIE" found |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2032 KB | Output is correct |
2 | Incorrect | 0 ms | 2032 KB | Expected integer, but "NIE" found |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 2172 KB | Expected integer, but "NIE" found |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 2500 KB | Expected integer, but "NIE" found |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 553 ms | 3656 KB | Expected integer, but "NIE" found |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 49 ms | 26700 KB | Expected integer, but "NIE" found |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1000 ms | 26700 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1000 ms | 8268 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |