# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
753840 |
2023-06-06T07:27:27 Z |
vjudge1 |
Tug of War (BOI15_tug) |
C++17 |
|
3000 ms |
17184 KB |
#include<bits/stdc++.h>
#define doi(i) if(!adj[i].size()) {cout << "NO\n";return 0;}if(adj[i].size()<2) {q.push(i);sum+=(i>n/2?1:-1)*((*begin(adj[i])).second);}
#define shift(x) ((x)>0?bt<<(x):bt>>(-x))
using namespace std;
multiset<pair<int, int>> adj[200100];
queue<int> q;
bool del[200100];
bitset<1200000> bt;
int tot;
void dfs(int n, int N) {
if (del[n]) return;
del[n] = true;
int nxt, cost;
tie(nxt, cost) = *adj[n].begin();
if(nxt>N)
tot += cost;
else
tot-=cost;
if (!del[nxt]) {
adj[nxt].erase(adj[nxt].find({n, cost}));
adj[n].clear();
dfs(nxt, N);
}
}
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int n, k, sum = 0;
cin >> n >> k;
n*=2;
for(int i = 1; i <= n; i++) {
int x, y, w;
cin >> x >> y >> w;
y+=n/2;
adj[x].insert({y,w});
adj[y].insert({x,w});
}
for(int i = 1; i <= n; i++) {
doi(i);
}
while(q.size()) {
int x = q.front(), i = (*adj[x].begin()).first, w= (*adj[x].begin()).second;
del[x] = 1;
q.pop();
adj[i].erase(adj[i].find({x,w}));
doi(i);
}
bt[sum+600000]=1;
for(int i = 1; i <= n; i++) {
if(!del[i]) {
tot = 0;
adj[i].erase(adj[i].begin());
dfs(i, n/2);
bt = shift(tot)|shift(-tot);
}
}
for(int i = -k; i <= k; i++) {
if(bt[600000+i]) {
cout << "YES\n";
return 0;
}
}
cout << "NO\n";
}
Compilation message
tug.cpp: In function 'void dfs(int, int)':
tug.cpp:17:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
17 | else
| ^~~~
tug.cpp:19:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
19 | if (!del[nxt]) {
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10452 KB |
Output is correct |
2 |
Correct |
8 ms |
10428 KB |
Output is correct |
3 |
Correct |
7 ms |
10412 KB |
Output is correct |
4 |
Correct |
7 ms |
10452 KB |
Output is correct |
5 |
Correct |
6 ms |
10452 KB |
Output is correct |
6 |
Correct |
7 ms |
10424 KB |
Output is correct |
7 |
Correct |
6 ms |
10452 KB |
Output is correct |
8 |
Correct |
7 ms |
10452 KB |
Output is correct |
9 |
Correct |
8 ms |
10420 KB |
Output is correct |
10 |
Correct |
7 ms |
10452 KB |
Output is correct |
11 |
Correct |
6 ms |
10452 KB |
Output is correct |
12 |
Correct |
8 ms |
10408 KB |
Output is correct |
13 |
Correct |
6 ms |
10424 KB |
Output is correct |
14 |
Correct |
7 ms |
10452 KB |
Output is correct |
15 |
Correct |
8 ms |
10428 KB |
Output is correct |
16 |
Correct |
7 ms |
10452 KB |
Output is correct |
17 |
Correct |
6 ms |
10452 KB |
Output is correct |
18 |
Correct |
7 ms |
10376 KB |
Output is correct |
19 |
Correct |
7 ms |
10452 KB |
Output is correct |
20 |
Correct |
7 ms |
10452 KB |
Output is correct |
21 |
Correct |
5 ms |
10068 KB |
Output is correct |
22 |
Correct |
6 ms |
10416 KB |
Output is correct |
23 |
Correct |
7 ms |
10452 KB |
Output is correct |
24 |
Correct |
6 ms |
10420 KB |
Output is correct |
25 |
Correct |
6 ms |
10452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10452 KB |
Output is correct |
2 |
Correct |
8 ms |
10428 KB |
Output is correct |
3 |
Correct |
7 ms |
10412 KB |
Output is correct |
4 |
Correct |
7 ms |
10452 KB |
Output is correct |
5 |
Correct |
6 ms |
10452 KB |
Output is correct |
6 |
Correct |
7 ms |
10424 KB |
Output is correct |
7 |
Correct |
6 ms |
10452 KB |
Output is correct |
8 |
Correct |
7 ms |
10452 KB |
Output is correct |
9 |
Correct |
8 ms |
10420 KB |
Output is correct |
10 |
Correct |
7 ms |
10452 KB |
Output is correct |
11 |
Correct |
6 ms |
10452 KB |
Output is correct |
12 |
Correct |
8 ms |
10408 KB |
Output is correct |
13 |
Correct |
6 ms |
10424 KB |
Output is correct |
14 |
Correct |
7 ms |
10452 KB |
Output is correct |
15 |
Correct |
8 ms |
10428 KB |
Output is correct |
16 |
Correct |
7 ms |
10452 KB |
Output is correct |
17 |
Correct |
6 ms |
10452 KB |
Output is correct |
18 |
Correct |
7 ms |
10376 KB |
Output is correct |
19 |
Correct |
7 ms |
10452 KB |
Output is correct |
20 |
Correct |
7 ms |
10452 KB |
Output is correct |
21 |
Correct |
5 ms |
10068 KB |
Output is correct |
22 |
Correct |
6 ms |
10416 KB |
Output is correct |
23 |
Correct |
7 ms |
10452 KB |
Output is correct |
24 |
Correct |
6 ms |
10420 KB |
Output is correct |
25 |
Correct |
6 ms |
10452 KB |
Output is correct |
26 |
Correct |
137 ms |
10864 KB |
Output is correct |
27 |
Correct |
27 ms |
10852 KB |
Output is correct |
28 |
Correct |
141 ms |
10864 KB |
Output is correct |
29 |
Correct |
28 ms |
10860 KB |
Output is correct |
30 |
Correct |
152 ms |
10864 KB |
Output is correct |
31 |
Correct |
27 ms |
10836 KB |
Output is correct |
32 |
Correct |
137 ms |
10940 KB |
Output is correct |
33 |
Correct |
37 ms |
10860 KB |
Output is correct |
34 |
Correct |
17 ms |
10812 KB |
Output is correct |
35 |
Correct |
25 ms |
10864 KB |
Output is correct |
36 |
Correct |
133 ms |
10864 KB |
Output is correct |
37 |
Correct |
29 ms |
10792 KB |
Output is correct |
38 |
Correct |
147 ms |
10864 KB |
Output is correct |
39 |
Correct |
33 ms |
10860 KB |
Output is correct |
40 |
Correct |
159 ms |
10836 KB |
Output is correct |
41 |
Correct |
28 ms |
10864 KB |
Output is correct |
42 |
Correct |
171 ms |
10880 KB |
Output is correct |
43 |
Correct |
26 ms |
10792 KB |
Output is correct |
44 |
Correct |
146 ms |
10864 KB |
Output is correct |
45 |
Correct |
25 ms |
10792 KB |
Output is correct |
46 |
Correct |
215 ms |
10872 KB |
Output is correct |
47 |
Correct |
11 ms |
10560 KB |
Output is correct |
48 |
Correct |
95 ms |
10812 KB |
Output is correct |
49 |
Correct |
80 ms |
10868 KB |
Output is correct |
50 |
Correct |
215 ms |
10872 KB |
Output is correct |
51 |
Correct |
153 ms |
10864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
411 ms |
12580 KB |
Output is correct |
2 |
Correct |
22 ms |
12216 KB |
Output is correct |
3 |
Correct |
464 ms |
12568 KB |
Output is correct |
4 |
Correct |
17 ms |
12264 KB |
Output is correct |
5 |
Correct |
524 ms |
12564 KB |
Output is correct |
6 |
Correct |
22 ms |
12244 KB |
Output is correct |
7 |
Correct |
485 ms |
12516 KB |
Output is correct |
8 |
Correct |
16 ms |
12160 KB |
Output is correct |
9 |
Correct |
525 ms |
12564 KB |
Output is correct |
10 |
Correct |
17 ms |
12276 KB |
Output is correct |
11 |
Correct |
504 ms |
12568 KB |
Output is correct |
12 |
Correct |
18 ms |
12244 KB |
Output is correct |
13 |
Correct |
515 ms |
12560 KB |
Output is correct |
14 |
Correct |
535 ms |
12568 KB |
Output is correct |
15 |
Correct |
24 ms |
12232 KB |
Output is correct |
16 |
Correct |
525 ms |
12564 KB |
Output is correct |
17 |
Correct |
16 ms |
12156 KB |
Output is correct |
18 |
Correct |
492 ms |
12564 KB |
Output is correct |
19 |
Correct |
16 ms |
12264 KB |
Output is correct |
20 |
Correct |
544 ms |
12564 KB |
Output is correct |
21 |
Correct |
16 ms |
12244 KB |
Output is correct |
22 |
Correct |
265 ms |
12596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10452 KB |
Output is correct |
2 |
Correct |
8 ms |
10428 KB |
Output is correct |
3 |
Correct |
7 ms |
10412 KB |
Output is correct |
4 |
Correct |
7 ms |
10452 KB |
Output is correct |
5 |
Correct |
6 ms |
10452 KB |
Output is correct |
6 |
Correct |
7 ms |
10424 KB |
Output is correct |
7 |
Correct |
6 ms |
10452 KB |
Output is correct |
8 |
Correct |
7 ms |
10452 KB |
Output is correct |
9 |
Correct |
8 ms |
10420 KB |
Output is correct |
10 |
Correct |
7 ms |
10452 KB |
Output is correct |
11 |
Correct |
6 ms |
10452 KB |
Output is correct |
12 |
Correct |
8 ms |
10408 KB |
Output is correct |
13 |
Correct |
6 ms |
10424 KB |
Output is correct |
14 |
Correct |
7 ms |
10452 KB |
Output is correct |
15 |
Correct |
8 ms |
10428 KB |
Output is correct |
16 |
Correct |
7 ms |
10452 KB |
Output is correct |
17 |
Correct |
6 ms |
10452 KB |
Output is correct |
18 |
Correct |
7 ms |
10376 KB |
Output is correct |
19 |
Correct |
7 ms |
10452 KB |
Output is correct |
20 |
Correct |
7 ms |
10452 KB |
Output is correct |
21 |
Correct |
5 ms |
10068 KB |
Output is correct |
22 |
Correct |
6 ms |
10416 KB |
Output is correct |
23 |
Correct |
7 ms |
10452 KB |
Output is correct |
24 |
Correct |
6 ms |
10420 KB |
Output is correct |
25 |
Correct |
6 ms |
10452 KB |
Output is correct |
26 |
Correct |
137 ms |
10864 KB |
Output is correct |
27 |
Correct |
27 ms |
10852 KB |
Output is correct |
28 |
Correct |
141 ms |
10864 KB |
Output is correct |
29 |
Correct |
28 ms |
10860 KB |
Output is correct |
30 |
Correct |
152 ms |
10864 KB |
Output is correct |
31 |
Correct |
27 ms |
10836 KB |
Output is correct |
32 |
Correct |
137 ms |
10940 KB |
Output is correct |
33 |
Correct |
37 ms |
10860 KB |
Output is correct |
34 |
Correct |
17 ms |
10812 KB |
Output is correct |
35 |
Correct |
25 ms |
10864 KB |
Output is correct |
36 |
Correct |
133 ms |
10864 KB |
Output is correct |
37 |
Correct |
29 ms |
10792 KB |
Output is correct |
38 |
Correct |
147 ms |
10864 KB |
Output is correct |
39 |
Correct |
33 ms |
10860 KB |
Output is correct |
40 |
Correct |
159 ms |
10836 KB |
Output is correct |
41 |
Correct |
28 ms |
10864 KB |
Output is correct |
42 |
Correct |
171 ms |
10880 KB |
Output is correct |
43 |
Correct |
26 ms |
10792 KB |
Output is correct |
44 |
Correct |
146 ms |
10864 KB |
Output is correct |
45 |
Correct |
25 ms |
10792 KB |
Output is correct |
46 |
Correct |
215 ms |
10872 KB |
Output is correct |
47 |
Correct |
11 ms |
10560 KB |
Output is correct |
48 |
Correct |
95 ms |
10812 KB |
Output is correct |
49 |
Correct |
80 ms |
10868 KB |
Output is correct |
50 |
Correct |
215 ms |
10872 KB |
Output is correct |
51 |
Correct |
153 ms |
10864 KB |
Output is correct |
52 |
Correct |
411 ms |
12580 KB |
Output is correct |
53 |
Correct |
22 ms |
12216 KB |
Output is correct |
54 |
Correct |
464 ms |
12568 KB |
Output is correct |
55 |
Correct |
17 ms |
12264 KB |
Output is correct |
56 |
Correct |
524 ms |
12564 KB |
Output is correct |
57 |
Correct |
22 ms |
12244 KB |
Output is correct |
58 |
Correct |
485 ms |
12516 KB |
Output is correct |
59 |
Correct |
16 ms |
12160 KB |
Output is correct |
60 |
Correct |
525 ms |
12564 KB |
Output is correct |
61 |
Correct |
17 ms |
12276 KB |
Output is correct |
62 |
Correct |
504 ms |
12568 KB |
Output is correct |
63 |
Correct |
18 ms |
12244 KB |
Output is correct |
64 |
Correct |
515 ms |
12560 KB |
Output is correct |
65 |
Correct |
535 ms |
12568 KB |
Output is correct |
66 |
Correct |
24 ms |
12232 KB |
Output is correct |
67 |
Correct |
525 ms |
12564 KB |
Output is correct |
68 |
Correct |
16 ms |
12156 KB |
Output is correct |
69 |
Correct |
492 ms |
12564 KB |
Output is correct |
70 |
Correct |
16 ms |
12264 KB |
Output is correct |
71 |
Correct |
544 ms |
12564 KB |
Output is correct |
72 |
Correct |
16 ms |
12244 KB |
Output is correct |
73 |
Correct |
265 ms |
12596 KB |
Output is correct |
74 |
Correct |
2542 ms |
16944 KB |
Output is correct |
75 |
Correct |
161 ms |
16928 KB |
Output is correct |
76 |
Correct |
2502 ms |
16932 KB |
Output is correct |
77 |
Correct |
149 ms |
16936 KB |
Output is correct |
78 |
Correct |
2480 ms |
16940 KB |
Output is correct |
79 |
Correct |
2269 ms |
16920 KB |
Output is correct |
80 |
Correct |
125 ms |
16936 KB |
Output is correct |
81 |
Correct |
167 ms |
17000 KB |
Output is correct |
82 |
Correct |
2161 ms |
16920 KB |
Output is correct |
83 |
Correct |
2510 ms |
17016 KB |
Output is correct |
84 |
Correct |
152 ms |
16844 KB |
Output is correct |
85 |
Correct |
2369 ms |
17064 KB |
Output is correct |
86 |
Correct |
142 ms |
16936 KB |
Output is correct |
87 |
Correct |
2509 ms |
16948 KB |
Output is correct |
88 |
Correct |
127 ms |
16940 KB |
Output is correct |
89 |
Correct |
2388 ms |
17184 KB |
Output is correct |
90 |
Correct |
149 ms |
16940 KB |
Output is correct |
91 |
Execution timed out |
3070 ms |
16936 KB |
Time limit exceeded |
92 |
Halted |
0 ms |
0 KB |
- |