# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566287 | 2022-05-22T08:14:03 Z | sofapuden | Ancient Books (IOI17_books) | C++14 | 1 ms | 340 KB |
#include "books.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; ll minimum_walk(vector<int> p, int s) { ll su = 0; int mx = 0; int n = p.size(); vector<int> vis(n,0); vector<int> cnt(n+1,0); ll ans = 0; int cn = 0; vector<vector<int>> gr(n+1); for(int i = 0; i < n; ++i){ if(!vis[i]){ cn++; while(!vis[i]){ ans+=abs(i-p[i]); vis[i] = cn; cnt[cn]++; i = p[i]; } } } int dif = 0; vector<int> cnt2(n+1,0); for(int i = 0; i < n; ++i){ if(!cnt2[vis[i]]++)dif++; if(cnt2[vis[i]] == cnt[vis[i]])dif--; if(!dif)ans+=2; } return ans-2; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 292 KB | Output is correct |
5 | Incorrect | 1 ms | 300 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 292 KB | Output is correct |
5 | Incorrect | 1 ms | 300 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 292 KB | Output is correct |
5 | Incorrect | 1 ms | 300 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | 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: '2744' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 292 KB | Output is correct |
5 | Incorrect | 1 ms | 300 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | Halted | 0 ms | 0 KB | - |