# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1080688 | 2024-08-29T12:49:48 Z | andrei_iorgulescu | 고대 책들 (IOI17_books) | C++14 | 1 ms | 4708 KB |
#include <bits/stdc++.h> #include "books.h" #warning That's not FB, that's my FB using namespace std; using ll = long long; int n, s; int p[1000005], pos[1000005]; vector<vector<int>> cyc; vector<int> cur; bool viz[1000005]; void dfs(int nod) { viz[nod] = true; cur.push_back(nod); if (!viz[p[nod]]) dfs(p[nod]); } ll minimum_walk(vector<int> PERM, int STR) { cyc.clear(); memset(viz,0,sizeof(viz)); n = PERM.size(); for (int i = 1; i <= n; i++) p[i] = PERM[i - 1] + 1, pos[p[i]] = i; s = STR; for (int i = 1; i <= n; i++) { if (!viz[i]) { cur.clear(); dfs(i); cyc.push_back(cur); } } ll ans = 0; for (auto it : cyc) if (it.size() != 1) ans = max(ans, 2ll * it[0]); for (auto it : cyc) { for (int i = 0; i + 1 < it.size(); i++) ans += abs(it[i] - it[i + 1]); } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4696 KB | Output is correct |
2 | Correct | 1 ms | 4708 KB | Output is correct |
3 | Correct | 1 ms | 4700 KB | Output is correct |
4 | Incorrect | 0 ms | 2652 KB | 3rd lines differ - on the 1st token, expected: '4', found: '5' |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4696 KB | Output is correct |
2 | Correct | 1 ms | 4708 KB | Output is correct |
3 | Correct | 1 ms | 4700 KB | Output is correct |
4 | Incorrect | 0 ms | 2652 KB | 3rd lines differ - on the 1st token, expected: '4', found: '5' |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4696 KB | Output is correct |
2 | Correct | 1 ms | 4708 KB | Output is correct |
3 | Correct | 1 ms | 4700 KB | Output is correct |
4 | Incorrect | 0 ms | 2652 KB | 3rd lines differ - on the 1st token, expected: '4', found: '5' |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 4700 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '3426' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4696 KB | Output is correct |
2 | Correct | 1 ms | 4708 KB | Output is correct |
3 | Correct | 1 ms | 4700 KB | Output is correct |
4 | Incorrect | 0 ms | 2652 KB | 3rd lines differ - on the 1st token, expected: '4', found: '5' |
5 | Halted | 0 ms | 0 KB | - |