# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
53752 | 2018-07-01T06:39:43 Z | 강한육군장홍준(#2037) | Islands (IOI08_islands) | C++11 | 2000 ms | 107636 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], 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]; } long long get_RD(int x) { if (edge[x].size() < 2)return 0; long long mx1=0, mxw, mx2=0; for (int nxt : edge[x])if (mx1 < D[nxt] + Y[nxt])mx1 = D[nxt] + Y[nxt], mxw = nxt; for (int nxt : edge[x])if (nxt != mxw&&mx2 < D[nxt] + Y[nxt])mx2 = D[nxt] + Y[nxt]; return mx1 + mx2; } 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, mx1 = -1e18,mx2 = -1e18; 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++) { res = max(res, max(L[i] + SV[i - 1] + mx1, L[i] + S - SV[i - 1] + mx2)); mx1 = max(mx1, L[i] - SV[i - 1]); mx2 = max(mx2, L[i] + SV[i - 1]); } ans += res; } printf("%lld", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 28792 KB | Output is correct |
2 | Correct | 25 ms | 28904 KB | Output is correct |
3 | Correct | 26 ms | 28904 KB | Output is correct |
4 | Correct | 25 ms | 29000 KB | Output is correct |
5 | Correct | 26 ms | 29056 KB | Output is correct |
6 | Correct | 26 ms | 29056 KB | Output is correct |
7 | Correct | 27 ms | 29056 KB | Output is correct |
8 | Correct | 26 ms | 29232 KB | Output is correct |
9 | Correct | 26 ms | 29232 KB | Output is correct |
10 | Correct | 26 ms | 29232 KB | Output is correct |
11 | Correct | 26 ms | 29232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 29244 KB | Output is correct |
2 | Correct | 33 ms | 29244 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 29244 KB | Output is correct |
2 | Correct | 28 ms | 29388 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 30076 KB | Output is correct |
2 | Correct | 46 ms | 31608 KB | Output is correct |
3 | Correct | 46 ms | 31608 KB | Output is correct |
4 | Correct | 37 ms | 31608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 32640 KB | Output is correct |
2 | Correct | 68 ms | 35504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 115 ms | 41728 KB | Output is correct |
2 | Correct | 110 ms | 44668 KB | Output is correct |
3 | Correct | 133 ms | 48048 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 325 ms | 53492 KB | Output is correct |
2 | Correct | 243 ms | 63356 KB | Output is correct |
3 | Correct | 239 ms | 69220 KB | Output is correct |
4 | Correct | 307 ms | 77416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 344 ms | 77416 KB | Output is correct |
2 | Correct | 685 ms | 92344 KB | Output is correct |
3 | Correct | 456 ms | 92344 KB | Output is correct |
4 | Correct | 494 ms | 96868 KB | Output is correct |
5 | Correct | 426 ms | 96868 KB | Output is correct |
6 | Correct | 1018 ms | 96868 KB | Output is correct |
7 | Correct | 448 ms | 103908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 424 ms | 103908 KB | Output is correct |
2 | Correct | 416 ms | 103908 KB | Output is correct |
3 | Correct | 477 ms | 107636 KB | Output is correct |
4 | Execution timed out | 2082 ms | 107636 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |