# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
561002 | 2022-05-12T07:33:06 Z | neki | Ancient Books (IOI17_books) | C++14 | 1 ms | 340 KB |
#include <bits/stdc++.h> #define ll long long #define vc vector #define all(a) a.begin(), a.end() #define fi first #define se second using namespace std; int minimum_walk(vc<int> p, int s){ ll n=p.size(); ll ans=0; vc<ll> doseg(n);iota(all(doseg), 0); vc<ll> vis(n, 0); for(ll i=0;i<n;++i) if(!vis[i]){ vc<ll> cyc; for(ll cur=i;1;){ vis[cur]=1; cyc.push_back(cur); ll nex=p[cur]; ans+=abs(nex-cur); if(nex==i)break; cur=nex; } ll zac=(*min_element(all(cyc))), konc=(*max_element(all(cyc))); doseg[konc]=min(doseg[konc], zac); } vc<pair<ll, ll>> ints; for(ll i=0;i<n;++i){ while(ints.size() and doseg[i]<=ints.back().second) ints.pop_back(); if(ints.size()==0) ints.emplace_back((ll)0, i); else ints.emplace_back(ints.back().second+1, i); } ll st;for(ll i=0;i<ints.size();++i) if(ints[i].fi<=s and s<=ints[i].se) st=i; //cout << st <<endl; ll fl=st;for(ll i=st-1;i>=0;--i) if(ints[i].fi!=ints[i].se) fl=i; ll fr=st;for(ll i=st+1;i<n;++i) if(ints[i].fi!=ints[i].se) fr=i; ans+=2 * (fr-fl); return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 308 KB | Output is correct |
2 | Correct | 1 ms | 296 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Incorrect | 1 ms | 296 KB | 3rd lines differ - on the 1st token, expected: '4', found: '8' |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 308 KB | Output is correct |
2 | Correct | 1 ms | 296 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Incorrect | 1 ms | 296 KB | 3rd lines differ - on the 1st token, expected: '4', found: '8' |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 308 KB | Output is correct |
2 | Correct | 1 ms | 296 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Incorrect | 1 ms | 296 KB | 3rd lines differ - on the 1st token, expected: '4', found: '8' |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '4064' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 308 KB | Output is correct |
2 | Correct | 1 ms | 296 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Incorrect | 1 ms | 296 KB | 3rd lines differ - on the 1st token, expected: '4', found: '8' |
5 | Halted | 0 ms | 0 KB | - |