# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384785 | 2021-04-02T09:30:17 Z | kshitij_sodani | Ancient Books (IOI17_books) | C++14 | 17 ms | 23916 KB |
//#pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long llo; #define mp make_pair #define pb push_back #define a first #define b second #define endl '\n' #include "books.h" llo ans=0; llo n; vector<llo> adj[1000001]; llo vis[1000001]; vector<llo> ss; void dfs(int no){ vis[no]=1; ss.pb(no); for(auto j:adj[no]){ if(vis[j]==0){ dfs(j); } } } long long minimum_walk(std::vector<int> p, int s) { n=p.size(); for(int i=0;i<n;i++){ adj[i].pb(p[i]); } llo co=0; llo ans=0; for(int i=0;i<n;i++){ if(vis[i]==0){ ss.clear(); dfs(i); co++; for(int j=0;j+1<ss.size();j++){ ans+=abs(ss[j]-ss[j+1]); } /* for(auto j:ss){ cout<<j<<",,"; } cout<<endl;*/ ans+=(abs(ss[0]-ss.back())); } } ans+=2*(co-1); return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23788 KB | Output is correct |
2 | Incorrect | 17 ms | 23788 KB | 3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23788 KB | Output is correct |
2 | Incorrect | 17 ms | 23788 KB | 3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23788 KB | Output is correct |
2 | Incorrect | 17 ms | 23788 KB | 3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 17 ms | 23916 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '4186' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23788 KB | Output is correct |
2 | Incorrect | 17 ms | 23788 KB | 3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 | Halted | 0 ms | 0 KB | - |