# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
120061 | 2019-06-23T07:15:43 Z | E869120 | Tug of War (BOI15_tug) | C++14 | 3000 ms | 14512 KB |
#include <iostream> #include <vector> #include <queue> #include <set> #include <bitset> using namespace std; #pragma warning (disable: 4996) bitset<1200001>F, H, I; bool solve(int N, int K, vector<int>G) { F.set(600000); for (int i = 0; i < G.size(); i++) { H = F; F = I; F |= (H << G[i]); F |= (H >> G[i]); } for (int i = 600000 - K; i <= 600000 + K; i++) { if (F[i] == 1) 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<int>Z; Z.push_back(abs(V1 - V2)); 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(abs(pa - pb)); } bool FinalAns = solve(N, K, Z); if (FinalAns == true) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 5120 KB | Output is correct |
2 | Correct | 8 ms | 5120 KB | Output is correct |
3 | Correct | 8 ms | 5120 KB | Output is correct |
4 | Correct | 8 ms | 5120 KB | Output is correct |
5 | Correct | 7 ms | 5120 KB | Output is correct |
6 | Correct | 9 ms | 5120 KB | Output is correct |
7 | Correct | 7 ms | 5120 KB | Output is correct |
8 | Correct | 8 ms | 5120 KB | Output is correct |
9 | Correct | 8 ms | 5120 KB | Output is correct |
10 | Correct | 7 ms | 5120 KB | Output is correct |
11 | Correct | 8 ms | 5120 KB | Output is correct |
12 | Correct | 8 ms | 5120 KB | Output is correct |
13 | Correct | 8 ms | 5120 KB | Output is correct |
14 | Correct | 7 ms | 5120 KB | Output is correct |
15 | Correct | 7 ms | 5120 KB | Output is correct |
16 | Correct | 10 ms | 5120 KB | Output is correct |
17 | Correct | 8 ms | 5120 KB | Output is correct |
18 | Correct | 7 ms | 5120 KB | Output is correct |
19 | Correct | 7 ms | 5120 KB | Output is correct |
20 | Correct | 7 ms | 5120 KB | Output is correct |
21 | Correct | 5 ms | 4608 KB | Output is correct |
22 | Correct | 7 ms | 5120 KB | Output is correct |
23 | Correct | 6 ms | 5120 KB | Output is correct |
24 | Correct | 8 ms | 5120 KB | Output is correct |
25 | Correct | 7 ms | 5120 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 5120 KB | Output is correct |
2 | Correct | 8 ms | 5120 KB | Output is correct |
3 | Correct | 8 ms | 5120 KB | Output is correct |
4 | Correct | 8 ms | 5120 KB | Output is correct |
5 | Correct | 7 ms | 5120 KB | Output is correct |
6 | Correct | 9 ms | 5120 KB | Output is correct |
7 | Correct | 7 ms | 5120 KB | Output is correct |
8 | Correct | 8 ms | 5120 KB | Output is correct |
9 | Correct | 8 ms | 5120 KB | Output is correct |
10 | Correct | 7 ms | 5120 KB | Output is correct |
11 | Correct | 8 ms | 5120 KB | Output is correct |
12 | Correct | 8 ms | 5120 KB | Output is correct |
13 | Correct | 8 ms | 5120 KB | Output is correct |
14 | Correct | 7 ms | 5120 KB | Output is correct |
15 | Correct | 7 ms | 5120 KB | Output is correct |
16 | Correct | 10 ms | 5120 KB | Output is correct |
17 | Correct | 8 ms | 5120 KB | Output is correct |
18 | Correct | 7 ms | 5120 KB | Output is correct |
19 | Correct | 7 ms | 5120 KB | Output is correct |
20 | Correct | 7 ms | 5120 KB | Output is correct |
21 | Correct | 5 ms | 4608 KB | Output is correct |
22 | Correct | 7 ms | 5120 KB | Output is correct |
23 | Correct | 6 ms | 5120 KB | Output is correct |
24 | Correct | 8 ms | 5120 KB | Output is correct |
25 | Correct | 7 ms | 5120 KB | Output is correct |
26 | Correct | 295 ms | 5760 KB | Output is correct |
27 | Correct | 50 ms | 5880 KB | Output is correct |
28 | Correct | 293 ms | 5760 KB | Output is correct |
29 | Correct | 48 ms | 5760 KB | Output is correct |
30 | Correct | 295 ms | 5760 KB | Output is correct |
31 | Correct | 51 ms | 5760 KB | Output is correct |
32 | Correct | 307 ms | 5760 KB | Output is correct |
33 | Correct | 48 ms | 5760 KB | Output is correct |
34 | Correct | 32 ms | 5792 KB | Output is correct |
35 | Correct | 49 ms | 5760 KB | Output is correct |
36 | Correct | 294 ms | 5808 KB | Output is correct |
37 | Correct | 48 ms | 5760 KB | Output is correct |
38 | Correct | 291 ms | 5804 KB | Output is correct |
39 | Correct | 48 ms | 5760 KB | Output is correct |
40 | Correct | 296 ms | 5804 KB | Output is correct |
41 | Correct | 49 ms | 5760 KB | Output is correct |
42 | Correct | 303 ms | 5804 KB | Output is correct |
43 | Correct | 47 ms | 5760 KB | Output is correct |
44 | Correct | 296 ms | 5808 KB | Output is correct |
45 | Correct | 50 ms | 5760 KB | Output is correct |
46 | Correct | 296 ms | 5792 KB | Output is correct |
47 | Correct | 8 ms | 4992 KB | Output is correct |
48 | Correct | 151 ms | 5632 KB | Output is correct |
49 | Correct | 158 ms | 5752 KB | Output is correct |
50 | Correct | 360 ms | 5760 KB | Output is correct |
51 | Correct | 307 ms | 5760 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 991 ms | 8276 KB | Output is correct |
2 | Correct | 23 ms | 6912 KB | Output is correct |
3 | Correct | 1029 ms | 8292 KB | Output is correct |
4 | Correct | 24 ms | 6912 KB | Output is correct |
5 | Correct | 1050 ms | 8316 KB | Output is correct |
6 | Correct | 23 ms | 6912 KB | Output is correct |
7 | Correct | 1247 ms | 8312 KB | Output is correct |
8 | Correct | 22 ms | 6912 KB | Output is correct |
9 | Correct | 1018 ms | 8288 KB | Output is correct |
10 | Correct | 25 ms | 6912 KB | Output is correct |
11 | Correct | 991 ms | 8288 KB | Output is correct |
12 | Correct | 20 ms | 6904 KB | Output is correct |
13 | Correct | 1016 ms | 8284 KB | Output is correct |
14 | Correct | 970 ms | 8288 KB | Output is correct |
15 | Correct | 18 ms | 6912 KB | Output is correct |
16 | Correct | 1018 ms | 8280 KB | Output is correct |
17 | Correct | 23 ms | 7040 KB | Output is correct |
18 | Correct | 975 ms | 8280 KB | Output is correct |
19 | Correct | 21 ms | 6904 KB | Output is correct |
20 | Correct | 994 ms | 8284 KB | Output is correct |
21 | Correct | 20 ms | 7012 KB | Output is correct |
22 | Correct | 505 ms | 7652 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 5120 KB | Output is correct |
2 | Correct | 8 ms | 5120 KB | Output is correct |
3 | Correct | 8 ms | 5120 KB | Output is correct |
4 | Correct | 8 ms | 5120 KB | Output is correct |
5 | Correct | 7 ms | 5120 KB | Output is correct |
6 | Correct | 9 ms | 5120 KB | Output is correct |
7 | Correct | 7 ms | 5120 KB | Output is correct |
8 | Correct | 8 ms | 5120 KB | Output is correct |
9 | Correct | 8 ms | 5120 KB | Output is correct |
10 | Correct | 7 ms | 5120 KB | Output is correct |
11 | Correct | 8 ms | 5120 KB | Output is correct |
12 | Correct | 8 ms | 5120 KB | Output is correct |
13 | Correct | 8 ms | 5120 KB | Output is correct |
14 | Correct | 7 ms | 5120 KB | Output is correct |
15 | Correct | 7 ms | 5120 KB | Output is correct |
16 | Correct | 10 ms | 5120 KB | Output is correct |
17 | Correct | 8 ms | 5120 KB | Output is correct |
18 | Correct | 7 ms | 5120 KB | Output is correct |
19 | Correct | 7 ms | 5120 KB | Output is correct |
20 | Correct | 7 ms | 5120 KB | Output is correct |
21 | Correct | 5 ms | 4608 KB | Output is correct |
22 | Correct | 7 ms | 5120 KB | Output is correct |
23 | Correct | 6 ms | 5120 KB | Output is correct |
24 | Correct | 8 ms | 5120 KB | Output is correct |
25 | Correct | 7 ms | 5120 KB | Output is correct |
26 | Correct | 295 ms | 5760 KB | Output is correct |
27 | Correct | 50 ms | 5880 KB | Output is correct |
28 | Correct | 293 ms | 5760 KB | Output is correct |
29 | Correct | 48 ms | 5760 KB | Output is correct |
30 | Correct | 295 ms | 5760 KB | Output is correct |
31 | Correct | 51 ms | 5760 KB | Output is correct |
32 | Correct | 307 ms | 5760 KB | Output is correct |
33 | Correct | 48 ms | 5760 KB | Output is correct |
34 | Correct | 32 ms | 5792 KB | Output is correct |
35 | Correct | 49 ms | 5760 KB | Output is correct |
36 | Correct | 294 ms | 5808 KB | Output is correct |
37 | Correct | 48 ms | 5760 KB | Output is correct |
38 | Correct | 291 ms | 5804 KB | Output is correct |
39 | Correct | 48 ms | 5760 KB | Output is correct |
40 | Correct | 296 ms | 5804 KB | Output is correct |
41 | Correct | 49 ms | 5760 KB | Output is correct |
42 | Correct | 303 ms | 5804 KB | Output is correct |
43 | Correct | 47 ms | 5760 KB | Output is correct |
44 | Correct | 296 ms | 5808 KB | Output is correct |
45 | Correct | 50 ms | 5760 KB | Output is correct |
46 | Correct | 296 ms | 5792 KB | Output is correct |
47 | Correct | 8 ms | 4992 KB | Output is correct |
48 | Correct | 151 ms | 5632 KB | Output is correct |
49 | Correct | 158 ms | 5752 KB | Output is correct |
50 | Correct | 360 ms | 5760 KB | Output is correct |
51 | Correct | 307 ms | 5760 KB | Output is correct |
52 | Correct | 991 ms | 8276 KB | Output is correct |
53 | Correct | 23 ms | 6912 KB | Output is correct |
54 | Correct | 1029 ms | 8292 KB | Output is correct |
55 | Correct | 24 ms | 6912 KB | Output is correct |
56 | Correct | 1050 ms | 8316 KB | Output is correct |
57 | Correct | 23 ms | 6912 KB | Output is correct |
58 | Correct | 1247 ms | 8312 KB | Output is correct |
59 | Correct | 22 ms | 6912 KB | Output is correct |
60 | Correct | 1018 ms | 8288 KB | Output is correct |
61 | Correct | 25 ms | 6912 KB | Output is correct |
62 | Correct | 991 ms | 8288 KB | Output is correct |
63 | Correct | 20 ms | 6904 KB | Output is correct |
64 | Correct | 1016 ms | 8284 KB | Output is correct |
65 | Correct | 970 ms | 8288 KB | Output is correct |
66 | Correct | 18 ms | 6912 KB | Output is correct |
67 | Correct | 1018 ms | 8280 KB | Output is correct |
68 | Correct | 23 ms | 7040 KB | Output is correct |
69 | Correct | 975 ms | 8280 KB | Output is correct |
70 | Correct | 21 ms | 6904 KB | Output is correct |
71 | Correct | 994 ms | 8284 KB | Output is correct |
72 | Correct | 20 ms | 7012 KB | Output is correct |
73 | Correct | 505 ms | 7652 KB | Output is correct |
74 | Execution timed out | 3073 ms | 14512 KB | Time limit exceeded |
75 | Halted | 0 ms | 0 KB | - |