# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
98932 | 2019-02-27T15:06:24 Z | square1001 | 고대 책들 (IOI17_books) | C++14 | 3 ms | 384 KB |
#include "books.h" #include <vector> #include <iostream> #include <algorithm> using namespace std; const long long inf = 1LL << 61; long long minimum_walk(std::vector<int> p, int s) { int n = p.size(); vector<pair<long long, long long> > cycles; vector<bool> vis(n); long long off = 0; for(int i = 0; i < n; ++i) { if(vis[i]) continue; long long cl = -inf, cr = inf; int pos = i; while(!vis[pos]) { if(pos <= s) cl = max(cl, (long long)pos); if(pos >= s) cr = min(cr, (long long)pos); vis[pos] = true; off += abs(p[pos] - pos); pos = p[pos]; } if(p[i] == i) continue; cycles.push_back(make_pair(cl - s, cr - s)); } sort(cycles.begin(), cycles.end()); /* for(pair<long long, long long> i : cycles) { cout << i.first << ' ' << i.second << endl; } * */ long long ans = inf, cur = 0; for(int i = 0; i <= cycles.size(); ++i) { ans = min(ans, (i != cycles.size() ? -cycles[i].first : 0) * 2 + cur * 2); if(i != cycles.size()) cur = max(cur, cycles[i].second); } return ans + off; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Incorrect | 2 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Incorrect | 2 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Incorrect | 2 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '4724' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Incorrect | 2 ms | 384 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |