# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
775848 | 2023-07-07T05:10:45 Z | Amylopectin | Ancient Books (IOI17_books) | C++14 | 1 ms | 300 KB |
#include "books.h" #include <vector> #include <algorithm> using namespace std; const long long mxn = 4e6 + 10; // const long long mxn = 20; struct we { long long le,ri; }; bool cmp(const struct we &l,const struct we &r) { return l.ri > r.ri; } struct we cyc[mxn] = {}; long long ta[mxn] = {},ru,u[mxn] = {}; long long fimi(long long l,long long r) { if(l < r) return l; return r; } long long fima(long long l,long long r) { if(l > r) return l; return r; } long long ab(long long l) { if(l < 0) return -l; return l; } long long minimum_walk(std::vector<int> pp, int sta) { long long i,j,n = pp.size(),m,cn,cm,fn,fm,su = 0,fii,cou ,ble = sta,bri = sta,cmi; for(i=0; i<n; i++) { ta[i] = pp[i]; } ru = 0; cyc[0] = {-1,n+1}; for(i=0; i<n; i++) { if(u[i] == 0) { cn = i; cou = 1; while(1) { if(cn <= sta) { cyc[ru].le = fima(cyc[ru].le,cn); } else { cyc[ru].ri = fimi(cyc[ru].ri,cn); } u[cn] = 1; su += ab(cn - ta[cn]); cn = ta[cn]; if(cn == i) { break; } cou ++; } if(cou == 1) { cyc[ru] = {-1,n+1}; } else if(cyc[ru].le == -1) { bri = fima(bri,cyc[ru].ri); cyc[ru] = {-1,n+1}; } else if(cyc[ru].ri == n+1) { ble = fimi(ble,cyc[ru].le); cyc[ru] = {-1,n+1}; } else { ru ++; cyc[ru] = {-1,n+1}; } } } sort(cyc,cyc+ru,cmp); cmi = n+1; for(i=0; i<ru; i++) { if(cyc[i].ri <= bri) { break; } cmi = fimi(cmi,cyc[i].ri - ble); ble = fimi(cyc[i].le,ble); } cmi = fimi(cmi,bri - ble); return su + cmi * 2; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 300 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '4724' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Incorrect | 0 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |