# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
613691 | 2022-07-30T09:22:55 Z | drdilyor | Ancient Books (IOI17_books) | C++17 | 7 ms | 304 KB |
#include <bits/stdc++.h> #include "books.h" #ifdef ONPC #include "t_debug.cpp" #else #define debug(...) 42 #endif #define sz(a) ((int)(a).size()) using namespace std; using ll = long long; const int INF = 1e9; const ll INFL = 1e18; const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count(); mt19937 rng(RANDOM); template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; } const int N = 2e5, LOGN = 17, MOD = 1e9+7; ll minimum_walk_0(vector<int> p, int s) { int n= sz(p); vector<int> done(n); function<int(int)> brute = [&](int cur) { int res = INF; for (int i = 0; i < n; i++) { if (done[i]) continue; if (p[i] == i) continue; done[i] = true; res = min(res, brute(p[i]) + abs(cur - i) + abs(i - p[i])); done[i] = false; } if (res == INF) return abs(cur - s); else return res; }; return brute(s); } long long minimum_walk(std::vector<int> p, int s) { int n = sz(p); debug(p, s); if (n <= 4) return minimum_walk_0(p, s); vector<int> right(n), left(n); for (int i = 0; i < n; i++) { if (p[i] > i) right[i] = p[i] - i; if (p[i] < i) left[i] = i - p[i]; } vector<int> res = {0}; for (int step = 0; step < n; step++) { bool found = false; for (int i = res.back(); i < n; i++) { if (right[i]) { found = true; right[i] = 0; res.push_back(i); i += right[i] - 1; } } for (int i = n-1; i >= 0; i--) { if (left[i]) { left[i] = 0; res.push_back(i); i -= left[i] - 1; } } } res.push_back(0); ll distance = 0; for (int i = 1; i < sz(res); i++) { distance += abs(res[i] - res[i-1]); } for (int i = 0; i < n; i++) { } return distance; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 304 KB | Output is correct |
6 | Incorrect | 1 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 304 KB | Output is correct |
6 | Incorrect | 1 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 304 KB | Output is correct |
6 | Incorrect | 1 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '1998' |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 304 KB | Output is correct |
6 | Incorrect | 1 ms | 212 KB | 3rd lines differ - on the 1st token, expected: '8', found: '10' |
7 | Halted | 0 ms | 0 KB | - |