Submission #753844

# Submission time Handle Problem Language Result Execution time Memory
753844 2023-06-06T07:34:25 Z vjudge1 Tug of War (BOI15_tug) C++17
100 / 100
2116 ms 16484 KB
#include<bits/stdc++.h>
#pragma GCC optimzize(2)
#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:2: warning: ignoring '#pragma GCC optimzize' [-Wunknown-pragmas]
    2 | #pragma GCC optimzize(2)
      | 
tug.cpp: In function 'void dfs(int, int)':
tug.cpp:18:5: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
   18 |     else
      |     ^~~~
tug.cpp:20:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
   20 |  if (!del[nxt]) {
      |  ^~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 10452 KB Output is correct
2 Correct 7 ms 10412 KB Output is correct
3 Correct 7 ms 10420 KB Output is correct
4 Correct 6 ms 10452 KB Output is correct
5 Correct 6 ms 10452 KB Output is correct
6 Correct 6 ms 10420 KB Output is correct
7 Correct 6 ms 10452 KB Output is correct
8 Correct 6 ms 10424 KB Output is correct
9 Correct 6 ms 10420 KB Output is correct
10 Correct 6 ms 10452 KB Output is correct
11 Correct 7 ms 10452 KB Output is correct
12 Correct 6 ms 10344 KB Output is correct
13 Correct 6 ms 10452 KB Output is correct
14 Correct 6 ms 10456 KB Output is correct
15 Correct 8 ms 10452 KB Output is correct
16 Correct 6 ms 10452 KB Output is correct
17 Correct 6 ms 10452 KB Output is correct
18 Correct 7 ms 10452 KB Output is correct
19 Correct 7 ms 10452 KB Output is correct
20 Correct 6 ms 10452 KB Output is correct
21 Correct 6 ms 10068 KB Output is correct
22 Correct 7 ms 10452 KB Output is correct
23 Correct 8 ms 10452 KB Output is correct
24 Correct 7 ms 10456 KB Output is correct
25 Correct 6 ms 10452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 10452 KB Output is correct
2 Correct 7 ms 10412 KB Output is correct
3 Correct 7 ms 10420 KB Output is correct
4 Correct 6 ms 10452 KB Output is correct
5 Correct 6 ms 10452 KB Output is correct
6 Correct 6 ms 10420 KB Output is correct
7 Correct 6 ms 10452 KB Output is correct
8 Correct 6 ms 10424 KB Output is correct
9 Correct 6 ms 10420 KB Output is correct
10 Correct 6 ms 10452 KB Output is correct
11 Correct 7 ms 10452 KB Output is correct
12 Correct 6 ms 10344 KB Output is correct
13 Correct 6 ms 10452 KB Output is correct
14 Correct 6 ms 10456 KB Output is correct
15 Correct 8 ms 10452 KB Output is correct
16 Correct 6 ms 10452 KB Output is correct
17 Correct 6 ms 10452 KB Output is correct
18 Correct 7 ms 10452 KB Output is correct
19 Correct 7 ms 10452 KB Output is correct
20 Correct 6 ms 10452 KB Output is correct
21 Correct 6 ms 10068 KB Output is correct
22 Correct 7 ms 10452 KB Output is correct
23 Correct 8 ms 10452 KB Output is correct
24 Correct 7 ms 10456 KB Output is correct
25 Correct 6 ms 10452 KB Output is correct
26 Correct 146 ms 10940 KB Output is correct
27 Correct 25 ms 10816 KB Output is correct
28 Correct 146 ms 10880 KB Output is correct
29 Correct 25 ms 10864 KB Output is correct
30 Correct 144 ms 10860 KB Output is correct
31 Correct 28 ms 10836 KB Output is correct
32 Correct 134 ms 10772 KB Output is correct
33 Correct 25 ms 10884 KB Output is correct
34 Correct 17 ms 10836 KB Output is correct
35 Correct 24 ms 10836 KB Output is correct
36 Correct 132 ms 10860 KB Output is correct
37 Correct 25 ms 10836 KB Output is correct
38 Correct 160 ms 10820 KB Output is correct
39 Correct 24 ms 10836 KB Output is correct
40 Correct 134 ms 10860 KB Output is correct
41 Correct 24 ms 10836 KB Output is correct
42 Correct 133 ms 10888 KB Output is correct
43 Correct 26 ms 10836 KB Output is correct
44 Correct 138 ms 10860 KB Output is correct
45 Correct 25 ms 10864 KB Output is correct
46 Correct 157 ms 10836 KB Output is correct
47 Correct 8 ms 10560 KB Output is correct
48 Correct 84 ms 10816 KB Output is correct
49 Correct 72 ms 10888 KB Output is correct
50 Correct 136 ms 10868 KB Output is correct
51 Correct 147 ms 10940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 374 ms 12568 KB Output is correct
2 Correct 14 ms 12244 KB Output is correct
3 Correct 419 ms 12752 KB Output is correct
4 Correct 15 ms 12264 KB Output is correct
5 Correct 423 ms 12580 KB Output is correct
6 Correct 14 ms 12232 KB Output is correct
7 Correct 429 ms 12560 KB Output is correct
8 Correct 15 ms 12280 KB Output is correct
9 Correct 387 ms 12576 KB Output is correct
10 Correct 15 ms 12244 KB Output is correct
11 Correct 430 ms 12568 KB Output is correct
12 Correct 18 ms 12108 KB Output is correct
13 Correct 382 ms 12460 KB Output is correct
14 Correct 422 ms 12464 KB Output is correct
15 Correct 16 ms 12116 KB Output is correct
16 Correct 378 ms 12468 KB Output is correct
17 Correct 15 ms 12116 KB Output is correct
18 Correct 452 ms 12496 KB Output is correct
19 Correct 14 ms 12172 KB Output is correct
20 Correct 453 ms 12344 KB Output is correct
21 Correct 14 ms 12036 KB Output is correct
22 Correct 200 ms 12352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 10452 KB Output is correct
2 Correct 7 ms 10412 KB Output is correct
3 Correct 7 ms 10420 KB Output is correct
4 Correct 6 ms 10452 KB Output is correct
5 Correct 6 ms 10452 KB Output is correct
6 Correct 6 ms 10420 KB Output is correct
7 Correct 6 ms 10452 KB Output is correct
8 Correct 6 ms 10424 KB Output is correct
9 Correct 6 ms 10420 KB Output is correct
10 Correct 6 ms 10452 KB Output is correct
11 Correct 7 ms 10452 KB Output is correct
12 Correct 6 ms 10344 KB Output is correct
13 Correct 6 ms 10452 KB Output is correct
14 Correct 6 ms 10456 KB Output is correct
15 Correct 8 ms 10452 KB Output is correct
16 Correct 6 ms 10452 KB Output is correct
17 Correct 6 ms 10452 KB Output is correct
18 Correct 7 ms 10452 KB Output is correct
19 Correct 7 ms 10452 KB Output is correct
20 Correct 6 ms 10452 KB Output is correct
21 Correct 6 ms 10068 KB Output is correct
22 Correct 7 ms 10452 KB Output is correct
23 Correct 8 ms 10452 KB Output is correct
24 Correct 7 ms 10456 KB Output is correct
25 Correct 6 ms 10452 KB Output is correct
26 Correct 146 ms 10940 KB Output is correct
27 Correct 25 ms 10816 KB Output is correct
28 Correct 146 ms 10880 KB Output is correct
29 Correct 25 ms 10864 KB Output is correct
30 Correct 144 ms 10860 KB Output is correct
31 Correct 28 ms 10836 KB Output is correct
32 Correct 134 ms 10772 KB Output is correct
33 Correct 25 ms 10884 KB Output is correct
34 Correct 17 ms 10836 KB Output is correct
35 Correct 24 ms 10836 KB Output is correct
36 Correct 132 ms 10860 KB Output is correct
37 Correct 25 ms 10836 KB Output is correct
38 Correct 160 ms 10820 KB Output is correct
39 Correct 24 ms 10836 KB Output is correct
40 Correct 134 ms 10860 KB Output is correct
41 Correct 24 ms 10836 KB Output is correct
42 Correct 133 ms 10888 KB Output is correct
43 Correct 26 ms 10836 KB Output is correct
44 Correct 138 ms 10860 KB Output is correct
45 Correct 25 ms 10864 KB Output is correct
46 Correct 157 ms 10836 KB Output is correct
47 Correct 8 ms 10560 KB Output is correct
48 Correct 84 ms 10816 KB Output is correct
49 Correct 72 ms 10888 KB Output is correct
50 Correct 136 ms 10868 KB Output is correct
51 Correct 147 ms 10940 KB Output is correct
52 Correct 374 ms 12568 KB Output is correct
53 Correct 14 ms 12244 KB Output is correct
54 Correct 419 ms 12752 KB Output is correct
55 Correct 15 ms 12264 KB Output is correct
56 Correct 423 ms 12580 KB Output is correct
57 Correct 14 ms 12232 KB Output is correct
58 Correct 429 ms 12560 KB Output is correct
59 Correct 15 ms 12280 KB Output is correct
60 Correct 387 ms 12576 KB Output is correct
61 Correct 15 ms 12244 KB Output is correct
62 Correct 430 ms 12568 KB Output is correct
63 Correct 18 ms 12108 KB Output is correct
64 Correct 382 ms 12460 KB Output is correct
65 Correct 422 ms 12464 KB Output is correct
66 Correct 16 ms 12116 KB Output is correct
67 Correct 378 ms 12468 KB Output is correct
68 Correct 15 ms 12116 KB Output is correct
69 Correct 452 ms 12496 KB Output is correct
70 Correct 14 ms 12172 KB Output is correct
71 Correct 453 ms 12344 KB Output is correct
72 Correct 14 ms 12036 KB Output is correct
73 Correct 200 ms 12352 KB Output is correct
74 Correct 1927 ms 16204 KB Output is correct
75 Correct 107 ms 16076 KB Output is correct
76 Correct 2091 ms 16252 KB Output is correct
77 Correct 117 ms 16124 KB Output is correct
78 Correct 1927 ms 16244 KB Output is correct
79 Correct 2012 ms 16256 KB Output is correct
80 Correct 105 ms 16076 KB Output is correct
81 Correct 118 ms 16076 KB Output is correct
82 Correct 1965 ms 16236 KB Output is correct
83 Correct 1999 ms 16128 KB Output is correct
84 Correct 113 ms 16076 KB Output is correct
85 Correct 1906 ms 16244 KB Output is correct
86 Correct 114 ms 16076 KB Output is correct
87 Correct 2078 ms 16368 KB Output is correct
88 Correct 116 ms 16084 KB Output is correct
89 Correct 1929 ms 16372 KB Output is correct
90 Correct 133 ms 16132 KB Output is correct
91 Correct 2058 ms 16236 KB Output is correct
92 Correct 121 ms 16124 KB Output is correct
93 Correct 2050 ms 16484 KB Output is correct
94 Correct 50 ms 15780 KB Output is correct
95 Correct 985 ms 16228 KB Output is correct
96 Correct 1020 ms 16224 KB Output is correct
97 Correct 2116 ms 16360 KB Output is correct
98 Correct 1956 ms 16244 KB Output is correct