# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
425491 | 2021-06-13T05:49:05 Z | Charis02 | 고대 책들 (IOI17_books) | C++14 | 1 ms | 332 KB |
#include "books.h" #include<iostream> #include<vector> #include<map> #define ll long long #define rep(i,a,b) for(int i = a;i < b;i++) #define mp(a,b) make_pair(a,b) #define N 100003 using namespace std; bool vis[N]; int abso(int x) { return (x < 0) ? -x : x; } ll get_cycle_cost(vector < int > c) { if(c.size()==1) return 0; ll res = 0; rep(i,1,c.size()) { res += abso(c[i]-c[i-1]); } res += abso(c[0]-c[c.size()-1]); return res; } long long minimum_walk(std::vector<int> p, int s) // for 1st sub { int n = p.size(); vector < vector < int > > cycles; rep(i,0,n) { if(vis[i]) continue; int cur = i; int ind = cycles.size(); cycles.push_back(vector < int >()); // cout << "here "; while(!vis[cur]) { // cout << cur << " "; vis[cur] = true; cycles[ind].push_back(cur); cur = p[cur]; } // cout << endl; } ll ans = 0; int last = 0; rep(i,0,cycles.size()) { ans += get_cycle_cost(cycles[i]); if(cycles[i].size() > 1) last = cycles[i][0]; } ans += last*2; return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 304 KB | Output is correct |
6 | Incorrect | 1 ms | 204 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 304 KB | Output is correct |
6 | Incorrect | 1 ms | 204 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 304 KB | Output is correct |
6 | Incorrect | 1 ms | 204 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 332 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '4728' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 304 KB | Output is correct |
6 | Incorrect | 1 ms | 204 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |