# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
292772 | 2020-09-07T13:13:37 Z | Saboon | 고대 책들 (IOI17_books) | C++17 | 23 ms | 32640 KB |
#include "books.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e6 + 10; bool visited[maxn], mark[maxn]; int c[maxn]; vector<pair<int,int>> g[maxn]; ll dp[maxn]; long long MST(int src){ ll ret = 0; memset(dp, 63, sizeof dp); dp[src] = 0; set<pair<ll,int>> S; S.insert({dp[src],src}); while (!S.empty()){ int v = (*S.begin()).second; S.erase(S.begin()); ret += dp[v]; for (auto [u,w] : g[v]){ if (dp[u] > dp[v]+w){ S.erase({dp[u],u}); dp[u] = dp[v]+w; S.insert({dp[u],u}); } } } return 2LL*ret; } long long minimum_walk(vector<int> p, int s){ int n = p.size(); set<int> S; ll answer = 0; for (int i = 0; i < n; i++) answer += abs(p[i]-i); int tmp = 0, Max, Min, last; Max = -1, last = -1; for (int i = s; i < n; i++){ if (!visited[i]){ mark[i] = 1; int x = i; if (i != s and i > Max) g[last].push_back({i+1,i-Max}); c[i] = i+1; while (!visited[x]){ visited[x] = 1; c[x] = c[i]; if (x > Max){ Max = x; last = c[x]; } x = p[x]; } } } Min = n, last = -1; memset(visited, 0, sizeof visited); for (int i = s; i >= 0; i--){ if (!visited[i]){ mark[i] = 1; int x = i; if (i != s and i < Min) g[last].push_back({i+1,Min-i}); if (c[i] == 0) c[i] = i+1; while (!visited[x]){ visited[x] = 1; c[x] = c[i]; if (Min > x){ Min = x; last = c[i]; } x = p[x]; } } } answer += MST(s+1); return answer; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 32640 KB | Output is correct |
2 | Correct | 22 ms | 32640 KB | Output is correct |
3 | Correct | 23 ms | 32640 KB | Output is correct |
4 | Correct | 22 ms | 32636 KB | Output is correct |
5 | Incorrect | 23 ms | 32640 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 32640 KB | Output is correct |
2 | Correct | 22 ms | 32640 KB | Output is correct |
3 | Correct | 23 ms | 32640 KB | Output is correct |
4 | Correct | 22 ms | 32636 KB | Output is correct |
5 | Incorrect | 23 ms | 32640 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 32640 KB | Output is correct |
2 | Correct | 22 ms | 32640 KB | Output is correct |
3 | Correct | 23 ms | 32640 KB | Output is correct |
4 | Correct | 22 ms | 32636 KB | Output is correct |
5 | Incorrect | 23 ms | 32640 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 22 ms | 32624 KB | 3rd lines differ - on the 1st token, expected: '3304', found: '4232' |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 32640 KB | Output is correct |
2 | Correct | 22 ms | 32640 KB | Output is correct |
3 | Correct | 23 ms | 32640 KB | Output is correct |
4 | Correct | 22 ms | 32636 KB | Output is correct |
5 | Incorrect | 23 ms | 32640 KB | 3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 | Halted | 0 ms | 0 KB | - |