# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1047204 | 2024-08-07T10:34:40 Z | Ahmed57 | Ancient Books (IOI17_books) | C++17 | 1 ms | 348 KB |
#include "bits/stdc++.h" using namespace std; vector<int> P; int vis[1001]; int mn = 1e9 ,mx = -1e9; void dfs(int i){ vis[i] = 1; mn = min(mn,i); mx = max(mx,i); if(!vis[P[i]])dfs(P[i]); } long long minimum_walk(vector<int> p, int s){ int ans = 0; int n = p.size(); P.clear(); for(int i = 0;i<n;i++){ vis[i] = 0; P.push_back(p[i]); ans+=abs(i-p[i]); } vector<pair<int,int>> lol; for(int i = 0;i<n;i++){ if(!vis[i]){ mn = 1e9 , mx = -1e9; dfs(i); lol.push_back({mn,mx}); } } sort(lol.begin(),lol.end()); int R = -1e9; int sz = 0; for(int i = 0;i<lol.size();i++){ if(R<lol[i].first){ R = lol[i].second; sz++; }else{ R = max(R,lol[i].second); } } ans+=(sz-1)*2; return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Incorrect | 0 ms | 348 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 | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Incorrect | 0 ms | 348 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 | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Incorrect | 0 ms | 348 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 | 348 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 | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Incorrect | 0 ms | 348 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | Halted | 0 ms | 0 KB | - |