# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
853663 |
2023-09-25T00:41:33 Z |
NK_ |
Tug of War (BOI15_tug) |
C++17 |
|
1702 ms |
10576 KB |
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
using db = long double;
template<class T> using pq = priority_queue<T, V<T>, greater<T>>;
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 18;
const int nax = 3e4 + 5;
const int kax = 20;
const int ZERO = nax * kax;
using B = bitset<2 * ZERO>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, K; cin >> N >> K;
int M = N; N += N;
vi deg(N); vi W(N);
V<set<pi>> adj(N); for(int i = 0; i < N; i++) {
int u, v, w; cin >> u >> v >> w; --u, --v, v += M;
W[i] = w;
adj[u].insert(mp(v, i));
adj[v].insert(mp(u, i));
}
queue<int> q; for(int i = 0; i < N; i++) {
if (!sz(adj[i])) {
cout << "NO" << nl;
exit(0-0);
}
if (sz(adj[i]) == 1) q.push(i);
}
int BAL = 0;
while(sz(q)) {
int u = q.front(); q.pop();
pi e = *begin(adj[u]);
adj[u].clear();
adj[e.f].erase(mp(u, e.s));
if (u < M) BAL += W[e.s];
else BAL -= W[e.s];
if (sz(adj[e.f]) == 1) q.push(e.f);
}
for(int i = 0; i < N; i++) {
if (sz(adj[i]) == 0) continue;
if (sz(adj[i]) != 2) {
cout << "NO" << nl;
exit(0-0);
}
}
int bal = 0;
function<void(int, int)> dfs = [&](int u, int d) {
if (sz(adj[u])) {
pi e = *begin(adj[u]);
adj[u].clear();
adj[e.f].erase(mp(u, e.s));
// cout << u << " " << e.s << endl;
bal += d * W[e.s];
dfs(e.f, -d);
}
};
vi X;
for(int u = 0; u < M; u++) if (sz(adj[u])) {
bal = 0; dfs(u, 1); X.pb(abs(bal));
}
B dp; dp[ZERO + BAL] = 1;
for(auto x : X) if (x) {
dp = (dp << x) | (dp >> x);
}
for(int x = 0; x < 2*ZERO; x++) if (dp[x]) {
// cout << x << endl;
if (abs(x - ZERO) <= K) {
cout << "YES" << nl;
exit(0-0);
}
}
cout << "NO" << nl;
exit(0-0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1112 KB |
Output is correct |
2 |
Correct |
2 ms |
1112 KB |
Output is correct |
3 |
Correct |
2 ms |
1112 KB |
Output is correct |
4 |
Correct |
2 ms |
1112 KB |
Output is correct |
5 |
Correct |
2 ms |
1112 KB |
Output is correct |
6 |
Correct |
2 ms |
1112 KB |
Output is correct |
7 |
Correct |
2 ms |
1112 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
2 ms |
1112 KB |
Output is correct |
10 |
Correct |
2 ms |
1112 KB |
Output is correct |
11 |
Correct |
2 ms |
1112 KB |
Output is correct |
12 |
Correct |
2 ms |
1112 KB |
Output is correct |
13 |
Correct |
2 ms |
1112 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
2 ms |
1112 KB |
Output is correct |
18 |
Correct |
2 ms |
1116 KB |
Output is correct |
19 |
Correct |
2 ms |
1112 KB |
Output is correct |
20 |
Correct |
2 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
856 KB |
Output is correct |
22 |
Correct |
1 ms |
1112 KB |
Output is correct |
23 |
Correct |
2 ms |
1116 KB |
Output is correct |
24 |
Correct |
2 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1112 KB |
Output is correct |
2 |
Correct |
2 ms |
1112 KB |
Output is correct |
3 |
Correct |
2 ms |
1112 KB |
Output is correct |
4 |
Correct |
2 ms |
1112 KB |
Output is correct |
5 |
Correct |
2 ms |
1112 KB |
Output is correct |
6 |
Correct |
2 ms |
1112 KB |
Output is correct |
7 |
Correct |
2 ms |
1112 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
2 ms |
1112 KB |
Output is correct |
10 |
Correct |
2 ms |
1112 KB |
Output is correct |
11 |
Correct |
2 ms |
1112 KB |
Output is correct |
12 |
Correct |
2 ms |
1112 KB |
Output is correct |
13 |
Correct |
2 ms |
1112 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
2 ms |
1112 KB |
Output is correct |
18 |
Correct |
2 ms |
1116 KB |
Output is correct |
19 |
Correct |
2 ms |
1112 KB |
Output is correct |
20 |
Correct |
2 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
856 KB |
Output is correct |
22 |
Correct |
1 ms |
1112 KB |
Output is correct |
23 |
Correct |
2 ms |
1116 KB |
Output is correct |
24 |
Correct |
2 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
1112 KB |
Output is correct |
26 |
Correct |
112 ms |
1624 KB |
Output is correct |
27 |
Correct |
18 ms |
1624 KB |
Output is correct |
28 |
Correct |
115 ms |
1624 KB |
Output is correct |
29 |
Correct |
20 ms |
1624 KB |
Output is correct |
30 |
Correct |
108 ms |
1624 KB |
Output is correct |
31 |
Correct |
18 ms |
1624 KB |
Output is correct |
32 |
Correct |
118 ms |
1792 KB |
Output is correct |
33 |
Correct |
19 ms |
1624 KB |
Output is correct |
34 |
Correct |
10 ms |
1628 KB |
Output is correct |
35 |
Correct |
18 ms |
1624 KB |
Output is correct |
36 |
Correct |
107 ms |
1628 KB |
Output is correct |
37 |
Correct |
18 ms |
1628 KB |
Output is correct |
38 |
Correct |
109 ms |
1624 KB |
Output is correct |
39 |
Correct |
18 ms |
1624 KB |
Output is correct |
40 |
Correct |
108 ms |
1784 KB |
Output is correct |
41 |
Correct |
18 ms |
1624 KB |
Output is correct |
42 |
Correct |
110 ms |
1624 KB |
Output is correct |
43 |
Correct |
18 ms |
1624 KB |
Output is correct |
44 |
Correct |
110 ms |
1624 KB |
Output is correct |
45 |
Correct |
18 ms |
1624 KB |
Output is correct |
46 |
Correct |
108 ms |
1788 KB |
Output is correct |
47 |
Correct |
2 ms |
1624 KB |
Output is correct |
48 |
Correct |
57 ms |
1624 KB |
Output is correct |
49 |
Correct |
57 ms |
1784 KB |
Output is correct |
50 |
Correct |
132 ms |
1624 KB |
Output is correct |
51 |
Correct |
115 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
3932 KB |
Output is correct |
2 |
Correct |
6 ms |
3928 KB |
Output is correct |
3 |
Correct |
8 ms |
3928 KB |
Output is correct |
4 |
Correct |
6 ms |
3928 KB |
Output is correct |
5 |
Correct |
8 ms |
3928 KB |
Output is correct |
6 |
Correct |
7 ms |
3932 KB |
Output is correct |
7 |
Correct |
8 ms |
3932 KB |
Output is correct |
8 |
Correct |
6 ms |
3932 KB |
Output is correct |
9 |
Correct |
8 ms |
3928 KB |
Output is correct |
10 |
Correct |
6 ms |
4184 KB |
Output is correct |
11 |
Correct |
8 ms |
3928 KB |
Output is correct |
12 |
Correct |
6 ms |
3928 KB |
Output is correct |
13 |
Correct |
8 ms |
3932 KB |
Output is correct |
14 |
Correct |
8 ms |
3928 KB |
Output is correct |
15 |
Correct |
6 ms |
3928 KB |
Output is correct |
16 |
Correct |
7 ms |
3928 KB |
Output is correct |
17 |
Correct |
6 ms |
3932 KB |
Output is correct |
18 |
Correct |
8 ms |
3928 KB |
Output is correct |
19 |
Correct |
6 ms |
3932 KB |
Output is correct |
20 |
Correct |
7 ms |
3928 KB |
Output is correct |
21 |
Correct |
8 ms |
3932 KB |
Output is correct |
22 |
Correct |
9 ms |
3928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1112 KB |
Output is correct |
2 |
Correct |
2 ms |
1112 KB |
Output is correct |
3 |
Correct |
2 ms |
1112 KB |
Output is correct |
4 |
Correct |
2 ms |
1112 KB |
Output is correct |
5 |
Correct |
2 ms |
1112 KB |
Output is correct |
6 |
Correct |
2 ms |
1112 KB |
Output is correct |
7 |
Correct |
2 ms |
1112 KB |
Output is correct |
8 |
Correct |
1 ms |
1116 KB |
Output is correct |
9 |
Correct |
2 ms |
1112 KB |
Output is correct |
10 |
Correct |
2 ms |
1112 KB |
Output is correct |
11 |
Correct |
2 ms |
1112 KB |
Output is correct |
12 |
Correct |
2 ms |
1112 KB |
Output is correct |
13 |
Correct |
2 ms |
1112 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
2 ms |
1112 KB |
Output is correct |
18 |
Correct |
2 ms |
1116 KB |
Output is correct |
19 |
Correct |
2 ms |
1112 KB |
Output is correct |
20 |
Correct |
2 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
856 KB |
Output is correct |
22 |
Correct |
1 ms |
1112 KB |
Output is correct |
23 |
Correct |
2 ms |
1116 KB |
Output is correct |
24 |
Correct |
2 ms |
1116 KB |
Output is correct |
25 |
Correct |
2 ms |
1112 KB |
Output is correct |
26 |
Correct |
112 ms |
1624 KB |
Output is correct |
27 |
Correct |
18 ms |
1624 KB |
Output is correct |
28 |
Correct |
115 ms |
1624 KB |
Output is correct |
29 |
Correct |
20 ms |
1624 KB |
Output is correct |
30 |
Correct |
108 ms |
1624 KB |
Output is correct |
31 |
Correct |
18 ms |
1624 KB |
Output is correct |
32 |
Correct |
118 ms |
1792 KB |
Output is correct |
33 |
Correct |
19 ms |
1624 KB |
Output is correct |
34 |
Correct |
10 ms |
1628 KB |
Output is correct |
35 |
Correct |
18 ms |
1624 KB |
Output is correct |
36 |
Correct |
107 ms |
1628 KB |
Output is correct |
37 |
Correct |
18 ms |
1628 KB |
Output is correct |
38 |
Correct |
109 ms |
1624 KB |
Output is correct |
39 |
Correct |
18 ms |
1624 KB |
Output is correct |
40 |
Correct |
108 ms |
1784 KB |
Output is correct |
41 |
Correct |
18 ms |
1624 KB |
Output is correct |
42 |
Correct |
110 ms |
1624 KB |
Output is correct |
43 |
Correct |
18 ms |
1624 KB |
Output is correct |
44 |
Correct |
110 ms |
1624 KB |
Output is correct |
45 |
Correct |
18 ms |
1624 KB |
Output is correct |
46 |
Correct |
108 ms |
1788 KB |
Output is correct |
47 |
Correct |
2 ms |
1624 KB |
Output is correct |
48 |
Correct |
57 ms |
1624 KB |
Output is correct |
49 |
Correct |
57 ms |
1784 KB |
Output is correct |
50 |
Correct |
132 ms |
1624 KB |
Output is correct |
51 |
Correct |
115 ms |
1792 KB |
Output is correct |
52 |
Correct |
8 ms |
3932 KB |
Output is correct |
53 |
Correct |
6 ms |
3928 KB |
Output is correct |
54 |
Correct |
8 ms |
3928 KB |
Output is correct |
55 |
Correct |
6 ms |
3928 KB |
Output is correct |
56 |
Correct |
8 ms |
3928 KB |
Output is correct |
57 |
Correct |
7 ms |
3932 KB |
Output is correct |
58 |
Correct |
8 ms |
3932 KB |
Output is correct |
59 |
Correct |
6 ms |
3932 KB |
Output is correct |
60 |
Correct |
8 ms |
3928 KB |
Output is correct |
61 |
Correct |
6 ms |
4184 KB |
Output is correct |
62 |
Correct |
8 ms |
3928 KB |
Output is correct |
63 |
Correct |
6 ms |
3928 KB |
Output is correct |
64 |
Correct |
8 ms |
3932 KB |
Output is correct |
65 |
Correct |
8 ms |
3928 KB |
Output is correct |
66 |
Correct |
6 ms |
3928 KB |
Output is correct |
67 |
Correct |
7 ms |
3928 KB |
Output is correct |
68 |
Correct |
6 ms |
3932 KB |
Output is correct |
69 |
Correct |
8 ms |
3928 KB |
Output is correct |
70 |
Correct |
6 ms |
3932 KB |
Output is correct |
71 |
Correct |
7 ms |
3928 KB |
Output is correct |
72 |
Correct |
8 ms |
3932 KB |
Output is correct |
73 |
Correct |
9 ms |
3928 KB |
Output is correct |
74 |
Correct |
1650 ms |
10348 KB |
Output is correct |
75 |
Correct |
86 ms |
10068 KB |
Output is correct |
76 |
Correct |
1631 ms |
10352 KB |
Output is correct |
77 |
Correct |
87 ms |
10072 KB |
Output is correct |
78 |
Correct |
1636 ms |
10356 KB |
Output is correct |
79 |
Correct |
1620 ms |
10352 KB |
Output is correct |
80 |
Correct |
90 ms |
10116 KB |
Output is correct |
81 |
Correct |
87 ms |
10064 KB |
Output is correct |
82 |
Correct |
1702 ms |
10108 KB |
Output is correct |
83 |
Correct |
1618 ms |
10348 KB |
Output is correct |
84 |
Correct |
92 ms |
10068 KB |
Output is correct |
85 |
Correct |
1627 ms |
10488 KB |
Output is correct |
86 |
Correct |
96 ms |
10116 KB |
Output is correct |
87 |
Correct |
1687 ms |
10352 KB |
Output is correct |
88 |
Correct |
86 ms |
9980 KB |
Output is correct |
89 |
Correct |
1663 ms |
10356 KB |
Output is correct |
90 |
Correct |
93 ms |
10072 KB |
Output is correct |
91 |
Correct |
1645 ms |
10576 KB |
Output is correct |
92 |
Correct |
84 ms |
10064 KB |
Output is correct |
93 |
Correct |
1628 ms |
10356 KB |
Output is correct |
94 |
Correct |
19 ms |
9812 KB |
Output is correct |
95 |
Correct |
822 ms |
10276 KB |
Output is correct |
96 |
Correct |
821 ms |
10276 KB |
Output is correct |
97 |
Correct |
1696 ms |
10576 KB |
Output is correct |
98 |
Correct |
1699 ms |
10352 KB |
Output is correct |