# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1000838 |
2024-06-18T09:59:15 Z |
LOLOLO |
Tug of War (BOI15_tug) |
C++17 |
|
1614 ms |
12780 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (ll)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 1e5 + 100;
set <pair <int, int>> ed[N];
bool used[N];
int st = 0, s[N];
pair <int, int> dfs(int u, int v) {
if (used[u])
return {0, 0};
used[u] = 1;
pair <int, int> A = {0, 0};
for (auto x : ed[u]) {
if (x.s == v)
continue;
A = dfs(x.f, x.s);
A.f += s[x.s];
swap(A.f, A.s);
}
return A;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
int S = 0;
for (int i = 1; i <= n * 2; i++) {
int l, r;
cin >> l >> r >> s[i];
ed[l].insert({r + n, i});
ed[r + n].insert({l, i});
S += s[i];
}
queue <int> pq;
int sz = n * 2;
for (int i = 1; i <= sz; i++) {
if (sz(ed[i]) == 0) {
cout << "NO\n";
return 0;
}
if (sz(ed[i]) == 1)
pq.push(i);
}
int L = 0;
while (sz(pq)) {
int t = pq.front();
pq.pop();
if (sz(ed[t]) == 0) {
continue;
}
auto it = *ed[t].begin();
int nxt = it.f, cost = it.s;
pair <int, int> pat = {t, cost};
ed[nxt].erase(pat);
ed[t].clear();
if (t <= n)
L += s[cost];
if (sz(ed[nxt]) == 1) {
pq.push(nxt);
}
}
for (int i = 1; i <= sz; i++) {
if (sz(ed[i]) > 2) {
cout << "NO\n";
return 0;
}
}
bitset <1000001> dp;
dp[0] = 1;
for (int i = 1; i <= sz; i++) {
if (sz(ed[i]) == 2 && used[i] == 0) {
auto it = *ed[i].begin();
pair <int, int> A = dfs(i, it.s);
dp = (dp << A.f) | (dp << A.s);
}
}
for (int i = 0; i <= 600000; i++) {
if (dp[i]) {
if (abs((S - (L + i)) - (L + i)) <= k) {
cout << "YES\n";
return 0;
}
}
}
cout << "NO\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
5976 KB |
Output is correct |
3 |
Correct |
2 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
5980 KB |
Output is correct |
5 |
Correct |
2 ms |
5976 KB |
Output is correct |
6 |
Correct |
2 ms |
5980 KB |
Output is correct |
7 |
Correct |
2 ms |
5980 KB |
Output is correct |
8 |
Correct |
2 ms |
5980 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
10 |
Correct |
2 ms |
5876 KB |
Output is correct |
11 |
Correct |
2 ms |
5980 KB |
Output is correct |
12 |
Correct |
2 ms |
5980 KB |
Output is correct |
13 |
Correct |
2 ms |
5980 KB |
Output is correct |
14 |
Correct |
2 ms |
5980 KB |
Output is correct |
15 |
Correct |
2 ms |
5980 KB |
Output is correct |
16 |
Correct |
2 ms |
5980 KB |
Output is correct |
17 |
Correct |
2 ms |
5980 KB |
Output is correct |
18 |
Correct |
2 ms |
5976 KB |
Output is correct |
19 |
Correct |
2 ms |
5980 KB |
Output is correct |
20 |
Correct |
2 ms |
5980 KB |
Output is correct |
21 |
Correct |
1 ms |
5724 KB |
Output is correct |
22 |
Correct |
1 ms |
5980 KB |
Output is correct |
23 |
Correct |
2 ms |
5980 KB |
Output is correct |
24 |
Correct |
2 ms |
5980 KB |
Output is correct |
25 |
Correct |
2 ms |
5980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
5976 KB |
Output is correct |
3 |
Correct |
2 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
5980 KB |
Output is correct |
5 |
Correct |
2 ms |
5976 KB |
Output is correct |
6 |
Correct |
2 ms |
5980 KB |
Output is correct |
7 |
Correct |
2 ms |
5980 KB |
Output is correct |
8 |
Correct |
2 ms |
5980 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
10 |
Correct |
2 ms |
5876 KB |
Output is correct |
11 |
Correct |
2 ms |
5980 KB |
Output is correct |
12 |
Correct |
2 ms |
5980 KB |
Output is correct |
13 |
Correct |
2 ms |
5980 KB |
Output is correct |
14 |
Correct |
2 ms |
5980 KB |
Output is correct |
15 |
Correct |
2 ms |
5980 KB |
Output is correct |
16 |
Correct |
2 ms |
5980 KB |
Output is correct |
17 |
Correct |
2 ms |
5980 KB |
Output is correct |
18 |
Correct |
2 ms |
5976 KB |
Output is correct |
19 |
Correct |
2 ms |
5980 KB |
Output is correct |
20 |
Correct |
2 ms |
5980 KB |
Output is correct |
21 |
Correct |
1 ms |
5724 KB |
Output is correct |
22 |
Correct |
1 ms |
5980 KB |
Output is correct |
23 |
Correct |
2 ms |
5980 KB |
Output is correct |
24 |
Correct |
2 ms |
5980 KB |
Output is correct |
25 |
Correct |
2 ms |
5980 KB |
Output is correct |
26 |
Correct |
96 ms |
6452 KB |
Output is correct |
27 |
Correct |
15 ms |
6232 KB |
Output is correct |
28 |
Correct |
111 ms |
6236 KB |
Output is correct |
29 |
Correct |
15 ms |
6236 KB |
Output is correct |
30 |
Correct |
94 ms |
6448 KB |
Output is correct |
31 |
Correct |
22 ms |
6236 KB |
Output is correct |
32 |
Correct |
100 ms |
6456 KB |
Output is correct |
33 |
Correct |
20 ms |
6236 KB |
Output is correct |
34 |
Correct |
12 ms |
6468 KB |
Output is correct |
35 |
Correct |
15 ms |
6232 KB |
Output is correct |
36 |
Correct |
96 ms |
6236 KB |
Output is correct |
37 |
Correct |
16 ms |
6232 KB |
Output is correct |
38 |
Correct |
94 ms |
6236 KB |
Output is correct |
39 |
Correct |
15 ms |
6232 KB |
Output is correct |
40 |
Correct |
94 ms |
6236 KB |
Output is correct |
41 |
Correct |
22 ms |
6232 KB |
Output is correct |
42 |
Correct |
97 ms |
6236 KB |
Output is correct |
43 |
Correct |
16 ms |
6232 KB |
Output is correct |
44 |
Correct |
97 ms |
6236 KB |
Output is correct |
45 |
Correct |
15 ms |
6232 KB |
Output is correct |
46 |
Correct |
99 ms |
6484 KB |
Output is correct |
47 |
Correct |
3 ms |
6236 KB |
Output is correct |
48 |
Correct |
48 ms |
6456 KB |
Output is correct |
49 |
Correct |
48 ms |
6236 KB |
Output is correct |
50 |
Correct |
94 ms |
6488 KB |
Output is correct |
51 |
Correct |
108 ms |
6232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
491 ms |
8024 KB |
Output is correct |
2 |
Correct |
7 ms |
7772 KB |
Output is correct |
3 |
Correct |
521 ms |
8028 KB |
Output is correct |
4 |
Correct |
8 ms |
7768 KB |
Output is correct |
5 |
Correct |
468 ms |
8016 KB |
Output is correct |
6 |
Correct |
7 ms |
7768 KB |
Output is correct |
7 |
Correct |
475 ms |
8028 KB |
Output is correct |
8 |
Correct |
7 ms |
7768 KB |
Output is correct |
9 |
Correct |
479 ms |
8012 KB |
Output is correct |
10 |
Correct |
7 ms |
7772 KB |
Output is correct |
11 |
Correct |
466 ms |
8016 KB |
Output is correct |
12 |
Correct |
8 ms |
7772 KB |
Output is correct |
13 |
Correct |
489 ms |
8028 KB |
Output is correct |
14 |
Correct |
483 ms |
8024 KB |
Output is correct |
15 |
Correct |
8 ms |
7772 KB |
Output is correct |
16 |
Correct |
465 ms |
8016 KB |
Output is correct |
17 |
Correct |
7 ms |
7772 KB |
Output is correct |
18 |
Correct |
474 ms |
8028 KB |
Output is correct |
19 |
Correct |
7 ms |
7772 KB |
Output is correct |
20 |
Correct |
473 ms |
8028 KB |
Output is correct |
21 |
Correct |
8 ms |
7772 KB |
Output is correct |
22 |
Correct |
280 ms |
8028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5976 KB |
Output is correct |
2 |
Correct |
3 ms |
5976 KB |
Output is correct |
3 |
Correct |
2 ms |
5980 KB |
Output is correct |
4 |
Correct |
2 ms |
5980 KB |
Output is correct |
5 |
Correct |
2 ms |
5976 KB |
Output is correct |
6 |
Correct |
2 ms |
5980 KB |
Output is correct |
7 |
Correct |
2 ms |
5980 KB |
Output is correct |
8 |
Correct |
2 ms |
5980 KB |
Output is correct |
9 |
Correct |
2 ms |
5980 KB |
Output is correct |
10 |
Correct |
2 ms |
5876 KB |
Output is correct |
11 |
Correct |
2 ms |
5980 KB |
Output is correct |
12 |
Correct |
2 ms |
5980 KB |
Output is correct |
13 |
Correct |
2 ms |
5980 KB |
Output is correct |
14 |
Correct |
2 ms |
5980 KB |
Output is correct |
15 |
Correct |
2 ms |
5980 KB |
Output is correct |
16 |
Correct |
2 ms |
5980 KB |
Output is correct |
17 |
Correct |
2 ms |
5980 KB |
Output is correct |
18 |
Correct |
2 ms |
5976 KB |
Output is correct |
19 |
Correct |
2 ms |
5980 KB |
Output is correct |
20 |
Correct |
2 ms |
5980 KB |
Output is correct |
21 |
Correct |
1 ms |
5724 KB |
Output is correct |
22 |
Correct |
1 ms |
5980 KB |
Output is correct |
23 |
Correct |
2 ms |
5980 KB |
Output is correct |
24 |
Correct |
2 ms |
5980 KB |
Output is correct |
25 |
Correct |
2 ms |
5980 KB |
Output is correct |
26 |
Correct |
96 ms |
6452 KB |
Output is correct |
27 |
Correct |
15 ms |
6232 KB |
Output is correct |
28 |
Correct |
111 ms |
6236 KB |
Output is correct |
29 |
Correct |
15 ms |
6236 KB |
Output is correct |
30 |
Correct |
94 ms |
6448 KB |
Output is correct |
31 |
Correct |
22 ms |
6236 KB |
Output is correct |
32 |
Correct |
100 ms |
6456 KB |
Output is correct |
33 |
Correct |
20 ms |
6236 KB |
Output is correct |
34 |
Correct |
12 ms |
6468 KB |
Output is correct |
35 |
Correct |
15 ms |
6232 KB |
Output is correct |
36 |
Correct |
96 ms |
6236 KB |
Output is correct |
37 |
Correct |
16 ms |
6232 KB |
Output is correct |
38 |
Correct |
94 ms |
6236 KB |
Output is correct |
39 |
Correct |
15 ms |
6232 KB |
Output is correct |
40 |
Correct |
94 ms |
6236 KB |
Output is correct |
41 |
Correct |
22 ms |
6232 KB |
Output is correct |
42 |
Correct |
97 ms |
6236 KB |
Output is correct |
43 |
Correct |
16 ms |
6232 KB |
Output is correct |
44 |
Correct |
97 ms |
6236 KB |
Output is correct |
45 |
Correct |
15 ms |
6232 KB |
Output is correct |
46 |
Correct |
99 ms |
6484 KB |
Output is correct |
47 |
Correct |
3 ms |
6236 KB |
Output is correct |
48 |
Correct |
48 ms |
6456 KB |
Output is correct |
49 |
Correct |
48 ms |
6236 KB |
Output is correct |
50 |
Correct |
94 ms |
6488 KB |
Output is correct |
51 |
Correct |
108 ms |
6232 KB |
Output is correct |
52 |
Correct |
491 ms |
8024 KB |
Output is correct |
53 |
Correct |
7 ms |
7772 KB |
Output is correct |
54 |
Correct |
521 ms |
8028 KB |
Output is correct |
55 |
Correct |
8 ms |
7768 KB |
Output is correct |
56 |
Correct |
468 ms |
8016 KB |
Output is correct |
57 |
Correct |
7 ms |
7768 KB |
Output is correct |
58 |
Correct |
475 ms |
8028 KB |
Output is correct |
59 |
Correct |
7 ms |
7768 KB |
Output is correct |
60 |
Correct |
479 ms |
8012 KB |
Output is correct |
61 |
Correct |
7 ms |
7772 KB |
Output is correct |
62 |
Correct |
466 ms |
8016 KB |
Output is correct |
63 |
Correct |
8 ms |
7772 KB |
Output is correct |
64 |
Correct |
489 ms |
8028 KB |
Output is correct |
65 |
Correct |
483 ms |
8024 KB |
Output is correct |
66 |
Correct |
8 ms |
7772 KB |
Output is correct |
67 |
Correct |
465 ms |
8016 KB |
Output is correct |
68 |
Correct |
7 ms |
7772 KB |
Output is correct |
69 |
Correct |
474 ms |
8028 KB |
Output is correct |
70 |
Correct |
7 ms |
7772 KB |
Output is correct |
71 |
Correct |
473 ms |
8028 KB |
Output is correct |
72 |
Correct |
8 ms |
7772 KB |
Output is correct |
73 |
Correct |
280 ms |
8028 KB |
Output is correct |
74 |
Correct |
1421 ms |
12664 KB |
Output is correct |
75 |
Correct |
73 ms |
12636 KB |
Output is correct |
76 |
Correct |
1509 ms |
12636 KB |
Output is correct |
77 |
Correct |
82 ms |
12628 KB |
Output is correct |
78 |
Correct |
1614 ms |
12624 KB |
Output is correct |
79 |
Correct |
1570 ms |
12632 KB |
Output is correct |
80 |
Correct |
71 ms |
12672 KB |
Output is correct |
81 |
Correct |
71 ms |
12624 KB |
Output is correct |
82 |
Correct |
1446 ms |
12680 KB |
Output is correct |
83 |
Correct |
1522 ms |
12684 KB |
Output is correct |
84 |
Correct |
72 ms |
12624 KB |
Output is correct |
85 |
Correct |
1487 ms |
12676 KB |
Output is correct |
86 |
Correct |
84 ms |
12632 KB |
Output is correct |
87 |
Correct |
1510 ms |
12680 KB |
Output is correct |
88 |
Correct |
107 ms |
12656 KB |
Output is correct |
89 |
Correct |
1591 ms |
12680 KB |
Output is correct |
90 |
Correct |
76 ms |
12380 KB |
Output is correct |
91 |
Correct |
1473 ms |
12632 KB |
Output is correct |
92 |
Correct |
83 ms |
12636 KB |
Output is correct |
93 |
Correct |
1402 ms |
12632 KB |
Output is correct |
94 |
Correct |
21 ms |
12376 KB |
Output is correct |
95 |
Correct |
758 ms |
12656 KB |
Output is correct |
96 |
Correct |
754 ms |
12780 KB |
Output is correct |
97 |
Correct |
1558 ms |
12676 KB |
Output is correct |
98 |
Correct |
1402 ms |
12632 KB |
Output is correct |