# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
120059 | 2019-06-23T07:09:27 Z | E869120 | Tug of War (BOI15_tug) | C++14 | 211 ms | 85468 KB |
#include <iostream> #include <vector> #include <queue> #include <set> using namespace std; #pragma warning (disable: 4996) bool dp[2009][80009]; bool solve(int N, int K, vector<pair<int, int>>G) { dp[0][40000] = true; for (int i = 0; i < G.size(); i++) { for (int j = 0; j <= 80000; j++) { if (dp[i][j] == false) continue; dp[i + 1][j + G[i].first] = true; dp[i + 1][j + G[i].second] = true; } } for (int i = 40000 - K; i <= 40000 + K; i++) { if (dp[G.size()][i] == true) return true; } return false; } set<pair<int, int>> G[60009]; int N, K, V1, V2, A[60009], B[60009], S[60009]; bool used[60009], colored[60009]; vector<pair<int, int>> X[60009]; int main() { scanf("%d%d", &N, &K); for (int i = 1; i <= N * 2; i++) { scanf("%d%d%d", &A[i], &B[i], &S[i]); G[A[i]].insert(make_pair(B[i] + N, i)); G[B[i] + N].insert(make_pair(A[i], i)); } queue<int>Q; for (int i = 1; i <= 2 * N; i++) { if (G[i].size() == 1) Q.push(i); } while (!Q.empty()) { int pos = Q.front(); Q.pop(); auto itr = G[pos].begin(); pair<int, int> E = (*itr); if (pos <= N) V1 += S[E.second]; else V2 += S[E.second]; used[E.second] = false; colored[pos] = true; G[pos].erase(make_pair(E.first, E.second)); G[E.first].erase(make_pair(pos, E.second)); if (G[E.first].size() == 1) Q.push(E.first); } for (int i = 1; i <= 2 * N; i++) { if (colored[i] == false && G[i].size() == 0) { cout << "NO" << endl; return 0; } } for (int i = 1; i <= 2 * N; i++) { auto itr = G[i].begin(); while (itr != G[i].end()) { X[i].push_back(*itr); itr++; } } vector<pair<int, int>>Z; Z.push_back(make_pair(V1 - V2, V2 - V1)); for (int i = 1; i <= 2 * N; i++) { if (colored[i] == true) continue; vector<int>E; if (X[i][0].first == X[i][1].first) { colored[i] = true; colored[X[i][0].first] = true; E.push_back(S[X[i][0].second]); E.push_back(S[X[i][1].second]); } else { int cx = i; while (true) { int nex = -1, cost = -1; for (int j = 0; j < X[cx].size(); j++) { if (colored[X[cx][j].first] == false) { nex = X[cx][j].first; cost = S[X[cx][j].second]; } } if (nex == -1) break; cx = nex; colored[cx] = true; E.push_back(cost); } } int pa = 0, pb = 0; for (int j = 0; j < E.size(); j++) { if (j % 2 == 0) pa += E[j]; else pb += E[j]; } Z.push_back(make_pair(pa - pb, pb - pa)); } bool FinalAns = solve(N, K, Z); if (FinalAns == true) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4608 KB | Output is correct |
2 | Correct | 6 ms | 4608 KB | Output is correct |
3 | Correct | 6 ms | 4608 KB | Output is correct |
4 | Correct | 6 ms | 4608 KB | Output is correct |
5 | Correct | 7 ms | 4608 KB | Output is correct |
6 | Correct | 6 ms | 4608 KB | Output is correct |
7 | Correct | 6 ms | 4608 KB | Output is correct |
8 | Correct | 8 ms | 4608 KB | Output is correct |
9 | Correct | 6 ms | 4608 KB | Output is correct |
10 | Correct | 6 ms | 4608 KB | Output is correct |
11 | Correct | 6 ms | 4608 KB | Output is correct |
12 | Correct | 6 ms | 4652 KB | Output is correct |
13 | Correct | 6 ms | 4608 KB | Output is correct |
14 | Correct | 6 ms | 4608 KB | Output is correct |
15 | Correct | 7 ms | 4608 KB | Output is correct |
16 | Correct | 6 ms | 4608 KB | Output is correct |
17 | Correct | 6 ms | 4648 KB | Output is correct |
18 | Correct | 6 ms | 4608 KB | Output is correct |
19 | Correct | 6 ms | 4608 KB | Output is correct |
20 | Correct | 6 ms | 4608 KB | Output is correct |
21 | Correct | 5 ms | 4608 KB | Output is correct |
22 | Correct | 5 ms | 4608 KB | Output is correct |
23 | Correct | 5 ms | 4608 KB | Output is correct |
24 | Correct | 6 ms | 4608 KB | Output is correct |
25 | Correct | 6 ms | 4608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4608 KB | Output is correct |
2 | Correct | 6 ms | 4608 KB | Output is correct |
3 | Correct | 6 ms | 4608 KB | Output is correct |
4 | Correct | 6 ms | 4608 KB | Output is correct |
5 | Correct | 7 ms | 4608 KB | Output is correct |
6 | Correct | 6 ms | 4608 KB | Output is correct |
7 | Correct | 6 ms | 4608 KB | Output is correct |
8 | Correct | 8 ms | 4608 KB | Output is correct |
9 | Correct | 6 ms | 4608 KB | Output is correct |
10 | Correct | 6 ms | 4608 KB | Output is correct |
11 | Correct | 6 ms | 4608 KB | Output is correct |
12 | Correct | 6 ms | 4652 KB | Output is correct |
13 | Correct | 6 ms | 4608 KB | Output is correct |
14 | Correct | 6 ms | 4608 KB | Output is correct |
15 | Correct | 7 ms | 4608 KB | Output is correct |
16 | Correct | 6 ms | 4608 KB | Output is correct |
17 | Correct | 6 ms | 4648 KB | Output is correct |
18 | Correct | 6 ms | 4608 KB | Output is correct |
19 | Correct | 6 ms | 4608 KB | Output is correct |
20 | Correct | 6 ms | 4608 KB | Output is correct |
21 | Correct | 5 ms | 4608 KB | Output is correct |
22 | Correct | 5 ms | 4608 KB | Output is correct |
23 | Correct | 5 ms | 4608 KB | Output is correct |
24 | Correct | 6 ms | 4608 KB | Output is correct |
25 | Correct | 6 ms | 4608 KB | Output is correct |
26 | Correct | 179 ms | 39548 KB | Output is correct |
27 | Correct | 37 ms | 17144 KB | Output is correct |
28 | Correct | 181 ms | 39288 KB | Output is correct |
29 | Correct | 37 ms | 17144 KB | Output is correct |
30 | Correct | 176 ms | 39652 KB | Output is correct |
31 | Correct | 36 ms | 17016 KB | Output is correct |
32 | Correct | 186 ms | 39480 KB | Output is correct |
33 | Correct | 38 ms | 17016 KB | Output is correct |
34 | Correct | 25 ms | 10476 KB | Output is correct |
35 | Correct | 38 ms | 17272 KB | Output is correct |
36 | Correct | 178 ms | 39812 KB | Output is correct |
37 | Correct | 37 ms | 17016 KB | Output is correct |
38 | Correct | 186 ms | 39928 KB | Output is correct |
39 | Correct | 39 ms | 17016 KB | Output is correct |
40 | Correct | 184 ms | 39200 KB | Output is correct |
41 | Correct | 39 ms | 17272 KB | Output is correct |
42 | Correct | 185 ms | 39928 KB | Output is correct |
43 | Correct | 39 ms | 17144 KB | Output is correct |
44 | Correct | 183 ms | 39984 KB | Output is correct |
45 | Correct | 38 ms | 17144 KB | Output is correct |
46 | Correct | 184 ms | 39288 KB | Output is correct |
47 | Correct | 8 ms | 5120 KB | Output is correct |
48 | Correct | 97 ms | 26408 KB | Output is correct |
49 | Correct | 95 ms | 26232 KB | Output is correct |
50 | Correct | 210 ms | 85468 KB | Output is correct |
51 | Correct | 210 ms | 85440 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 211 ms | 31820 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4608 KB | Output is correct |
2 | Correct | 6 ms | 4608 KB | Output is correct |
3 | Correct | 6 ms | 4608 KB | Output is correct |
4 | Correct | 6 ms | 4608 KB | Output is correct |
5 | Correct | 7 ms | 4608 KB | Output is correct |
6 | Correct | 6 ms | 4608 KB | Output is correct |
7 | Correct | 6 ms | 4608 KB | Output is correct |
8 | Correct | 8 ms | 4608 KB | Output is correct |
9 | Correct | 6 ms | 4608 KB | Output is correct |
10 | Correct | 6 ms | 4608 KB | Output is correct |
11 | Correct | 6 ms | 4608 KB | Output is correct |
12 | Correct | 6 ms | 4652 KB | Output is correct |
13 | Correct | 6 ms | 4608 KB | Output is correct |
14 | Correct | 6 ms | 4608 KB | Output is correct |
15 | Correct | 7 ms | 4608 KB | Output is correct |
16 | Correct | 6 ms | 4608 KB | Output is correct |
17 | Correct | 6 ms | 4648 KB | Output is correct |
18 | Correct | 6 ms | 4608 KB | Output is correct |
19 | Correct | 6 ms | 4608 KB | Output is correct |
20 | Correct | 6 ms | 4608 KB | Output is correct |
21 | Correct | 5 ms | 4608 KB | Output is correct |
22 | Correct | 5 ms | 4608 KB | Output is correct |
23 | Correct | 5 ms | 4608 KB | Output is correct |
24 | Correct | 6 ms | 4608 KB | Output is correct |
25 | Correct | 6 ms | 4608 KB | Output is correct |
26 | Correct | 179 ms | 39548 KB | Output is correct |
27 | Correct | 37 ms | 17144 KB | Output is correct |
28 | Correct | 181 ms | 39288 KB | Output is correct |
29 | Correct | 37 ms | 17144 KB | Output is correct |
30 | Correct | 176 ms | 39652 KB | Output is correct |
31 | Correct | 36 ms | 17016 KB | Output is correct |
32 | Correct | 186 ms | 39480 KB | Output is correct |
33 | Correct | 38 ms | 17016 KB | Output is correct |
34 | Correct | 25 ms | 10476 KB | Output is correct |
35 | Correct | 38 ms | 17272 KB | Output is correct |
36 | Correct | 178 ms | 39812 KB | Output is correct |
37 | Correct | 37 ms | 17016 KB | Output is correct |
38 | Correct | 186 ms | 39928 KB | Output is correct |
39 | Correct | 39 ms | 17016 KB | Output is correct |
40 | Correct | 184 ms | 39200 KB | Output is correct |
41 | Correct | 39 ms | 17272 KB | Output is correct |
42 | Correct | 185 ms | 39928 KB | Output is correct |
43 | Correct | 39 ms | 17144 KB | Output is correct |
44 | Correct | 183 ms | 39984 KB | Output is correct |
45 | Correct | 38 ms | 17144 KB | Output is correct |
46 | Correct | 184 ms | 39288 KB | Output is correct |
47 | Correct | 8 ms | 5120 KB | Output is correct |
48 | Correct | 97 ms | 26408 KB | Output is correct |
49 | Correct | 95 ms | 26232 KB | Output is correct |
50 | Correct | 210 ms | 85468 KB | Output is correct |
51 | Correct | 210 ms | 85440 KB | Output is correct |
52 | Runtime error | 211 ms | 31820 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
53 | Halted | 0 ms | 0 KB | - |