# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1045333 | 2024-08-05T20:33:32 Z | beaconmc | 고대 책들 (IOI17_books) | C++14 | 1 ms | 348 KB |
#include "books.h" #include <bits/stdc++.h> typedef long long ll; #define FOR(i,x,y) for(ll i=x; i<y; i++) #define FORNEG(i,x,y) for(ll i=x; i>y; i--) using namespace std; long long minimum_walk(vector<int> p, int s) { vector<int> q; for (auto&i : p)q.push_back(i); sort(q.begin(), q.end()); if (p==q) return 0; vector<bool> visited; vector<ll> maxis; for (auto&i : p) visited.push_back(0), maxis.push_back(-1); FOR(i,0,p.size()){ vector<ll> stuff; ll temp = i; ll maxi = i; if (visited[temp]) continue; visited[temp] = 1; temp = p[temp]; stuff.push_back(temp); while (temp != i){ maxi = max(maxi, temp); visited[temp] = 1; temp = p[temp]; visited[temp] = 1; stuff.push_back(temp); } for (auto&k : stuff){ maxis[k] = maxi; } } ll cur = 0; ll ans = 0; FOR(i,0,p.size()){ ans += abs(p[i]-i); } while (cur < p.size()-1){ if (cur == maxis[cur]){ ans+=2, cur++; } else cur = maxis[cur]; } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Incorrect | 0 ms | 348 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Incorrect | 0 ms | 348 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Incorrect | 0 ms | 348 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 344 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Incorrect | 0 ms | 348 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | Halted | 0 ms | 0 KB | - |