# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
53742 | 2018-07-01T06:21:06 Z | 강한육군장홍준(#2037) | Islands (IOI08_islands) | C++11 | 2000 ms | 99608 KB |
#include<stdio.h> #include<vector> #include<algorithm> using namespace std; vector<int>edge[1212121]; long long RD[1212121], D[1212121], X[1212121], Y[1212121], indeg[1212121], ck[1212121], SV[1212121], L[1212121], V[1212121]; long long max(long long a, long long b) { if (a < b)return b; return a; } bool sort_DY(int a, int b) { return D[a] + Y[a] > D[b] + Y[b]; } int get_RD(int x) { if (edge[x].size() < 2)return 0; sort(edge[x].begin(), edge[x].end(), sort_DY); return D[edge[x][0]] + D[edge[x][1]] + Y[edge[x][0]] + Y[edge[x][1]]; } int main() { vector<long long>Q; long long n, i, j; scanf("%lld", &n); for (i = 1; i <= n; i++) scanf("%lld%lld", &X[i], &Y[i]), indeg[X[i]]++, edge[X[i]].push_back(i); for (i = 1; i <= n; i++)if (indeg[i] == 0)Q.push_back(i); while (!Q.empty()) { long long now = Q.back(); Q.pop_back(); RD[now] = max(RD[now], get_RD(now)); RD[X[now]] = max(RD[X[now]], RD[now]); D[X[now]] = max(D[X[now]], D[now] + Y[now]); if (--indeg[X[now]] == 0)Q.push_back(X[now]); X[now] = 0; } long long ans = 0; for (i = 1; i <= n; i++) if(X[i]){ long long now = i, S = 0, sz = 0, res = 0; while (X[now]) { L[++sz] = D[now]; V[sz] = Y[now]; res = max(res, max(RD[now], get_RD(now))); S += Y[now]; long long tmp = now; now = X[now]; X[tmp] = 0; } for (i = 1; i <= sz; i++)SV[i] = SV[i - 1] + V[i]; for (i = 1; i <= sz; i++) { for (j = i + 1; j <= sz; j++) { res = max(res, L[i] + L[j] + max(SV[j-1]-SV[i-1], S - (SV[j-1] - SV[i-1]))); } } ans += res; } printf("%lld", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 28792 KB | Output is correct |
2 | Correct | 26 ms | 28904 KB | Output is correct |
3 | Correct | 27 ms | 29092 KB | Output is correct |
4 | Correct | 26 ms | 29092 KB | Output is correct |
5 | Correct | 29 ms | 29192 KB | Output is correct |
6 | Correct | 29 ms | 29192 KB | Output is correct |
7 | Correct | 26 ms | 29192 KB | Output is correct |
8 | Correct | 28 ms | 29192 KB | Output is correct |
9 | Correct | 27 ms | 29192 KB | Output is correct |
10 | Correct | 27 ms | 29192 KB | Output is correct |
11 | Correct | 26 ms | 29192 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 29192 KB | Output is correct |
2 | Correct | 29 ms | 29192 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 28 ms | 29292 KB | Output is correct |
2 | Correct | 32 ms | 29412 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 30056 KB | Output is correct |
2 | Correct | 254 ms | 31592 KB | Output is correct |
3 | Correct | 41 ms | 31592 KB | Output is correct |
4 | Correct | 32 ms | 31592 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 394 ms | 32636 KB | Output is correct |
2 | Correct | 567 ms | 35572 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 452 ms | 41712 KB | Output is correct |
2 | Execution timed out | 2062 ms | 44540 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1472 ms | 53500 KB | Output is correct |
2 | Execution timed out | 2044 ms | 63336 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 728 ms | 64500 KB | Output is correct |
2 | Execution timed out | 2066 ms | 92268 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 461 ms | 99608 KB | Output is correct |
2 | Incorrect | 421 ms | 99608 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |