# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
248908 | 2020-07-13T17:36:34 Z | kostia244 | Ancient Books (IOI17_books) | C++17 | 1 ms | 384 KB |
#include "books.h" #include<bits/extc++.h> using namespace std; const int maxn = 1<<20; using ll = long long; using namespace __gnu_pbds; using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; ll vis[maxn][4]; ll minimum_walk(vector<int> p, int s) { oset pref, suf; vector<int> pos(p.size()); ll ans = 0, lst = 0; for(int i = 0; i < p.size(); i++) suf.insert(i), pos[p[i]] = i; for(int t, i = 0; i < p.size(); i++) { //cout << i << "::\n"; int v = p[i]; suf.erase(v); if(i != v) { vis[i][(v > i)*3]++; vis[i][1 + (pos[i]>i)]++; } t = pref.size()-pref.order_of_key(i+1); vis[i][1] += t, vis[i][3] += t; t = suf.order_of_key(i); vis[i][0] += t, vis[i][2] += t; vis[i][2] = vis[i][3] = max(vis[i][2], vis[i][3]); vis[i][0] = vis[i][1] = max(vis[i][0], vis[i][1]); pref.insert(v); ans += (vis[i][0] + vis[i][2]); if(vis[i][0] + vis[i][2]) lst = i; //for(int j = 0; j < 4; j++) cout << vis[i][j] << " "; cout << endl; } for(int i = 0; i <= lst; i++) ans += 2*!(vis[i][0]+vis[i][2]); return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 256 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Incorrect | 0 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '0', found: '2' |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 256 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Incorrect | 0 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '0', found: '2' |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 256 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Incorrect | 0 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '0', found: '2' |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 256 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Incorrect | 0 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '0', found: '2' |
10 | Halted | 0 ms | 0 KB | - |