# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
887615 |
2023-12-14T20:25:11 Z |
Shayan86 |
Tug of War (BOI15_tug) |
C++17 |
|
358 ms |
4912 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define Mp make_pair
#define sep ' '
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define kill(res) cout << res << '\n', exit(0);
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 6e4 + 50;
const ll Mod = 1e9 + 7;
ll n, k, s[N], par[N], h[N], f[N], sum, cnt;
pair<pii, int> edge;
bool mark[N];
vector<ll> vec;
vector<pii> adj[N];
void dfs(int v){
mark[v] = 1;
for(auto [u, w]: adj[v]){
if(u == par[v]) continue;
else if(mark[u]){
edge = Mp(Mp(v, u), w);
continue;
}
par[u] = v; h[u] = h[v] + 1; f[u] = w - f[v]; dfs(u);
if(h[v] % 2) sum += w;
else sum -= w;
}
}
const ll M = 10 * N;
bitset<2*M> diff;
void check(int v){
mark[v] = 1;
for(auto [u, w]: adj[v]){
if(!mark[u]) check(u);
}
cnt++; sum += adj[v].size();
}
int main(){
fast_io;
cin >> n >> k;
int l, r;
for(int i = 1; i <= 2*n; i++){
cin >> l >> r >> s[i]; r += n;
adj[l].pb(Mp(r, s[i]));
adj[r].pb(Mp(l, s[i]));
}
for(int i = 1; i <= 2*n; i++){
if(!mark[i]){
sum = 0; cnt = 0; check(i);
if(sum != cnt * 2) kill("NO");
}
}
fill(mark, mark + N, 0);
diff[M] = 1;
for(int i = 1; i <= 2*n; i++){
if(!mark[i]){
sum = 0; dfs(i);
int v = edge.F.F;
int u = edge.F.S;
int w = edge.S;
if(h[v] % 2) sum -= w;
else sum += w;
ll sum2 = sum; // f[u] + f[v] - w
if(h[v] % 2) sum2 -= (f[u] + f[v] - w);
else sum2 += (f[u] + f[v] - w);
if(sum2 >= 0) diff = diff << sum2;
else diff = diff >> (-sum2);
vec.pb(abs(sum - sum2));
//cout << sum2 << sep << sum - sum2 << endl;
}
}
for(auto x: vec){
diff = (diff >> x) | (diff << x);
}
ll res = Mod;
for(int i = 0; i < 2*M; i++) if(diff[i]) res = min(res, abs(M-i));
//cout << res << endl;
if(res <= k) cout << "YES";
else cout << "NO";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Correct |
2 ms |
3416 KB |
Output is correct |
5 |
Correct |
2 ms |
3420 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
3 ms |
3420 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
2 ms |
3420 KB |
Output is correct |
12 |
Correct |
2 ms |
3420 KB |
Output is correct |
13 |
Correct |
2 ms |
3420 KB |
Output is correct |
14 |
Correct |
2 ms |
3432 KB |
Output is correct |
15 |
Correct |
2 ms |
3420 KB |
Output is correct |
16 |
Correct |
2 ms |
3428 KB |
Output is correct |
17 |
Correct |
2 ms |
3420 KB |
Output is correct |
18 |
Correct |
3 ms |
3420 KB |
Output is correct |
19 |
Correct |
2 ms |
3384 KB |
Output is correct |
20 |
Correct |
2 ms |
3416 KB |
Output is correct |
21 |
Correct |
1 ms |
2908 KB |
Output is correct |
22 |
Correct |
2 ms |
3420 KB |
Output is correct |
23 |
Correct |
2 ms |
3420 KB |
Output is correct |
24 |
Correct |
2 ms |
3420 KB |
Output is correct |
25 |
Correct |
2 ms |
3420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Correct |
2 ms |
3416 KB |
Output is correct |
5 |
Correct |
2 ms |
3420 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
3 ms |
3420 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
2 ms |
3420 KB |
Output is correct |
12 |
Correct |
2 ms |
3420 KB |
Output is correct |
13 |
Correct |
2 ms |
3420 KB |
Output is correct |
14 |
Correct |
2 ms |
3432 KB |
Output is correct |
15 |
Correct |
2 ms |
3420 KB |
Output is correct |
16 |
Correct |
2 ms |
3428 KB |
Output is correct |
17 |
Correct |
2 ms |
3420 KB |
Output is correct |
18 |
Correct |
3 ms |
3420 KB |
Output is correct |
19 |
Correct |
2 ms |
3384 KB |
Output is correct |
20 |
Correct |
2 ms |
3416 KB |
Output is correct |
21 |
Correct |
1 ms |
2908 KB |
Output is correct |
22 |
Correct |
2 ms |
3420 KB |
Output is correct |
23 |
Correct |
2 ms |
3420 KB |
Output is correct |
24 |
Correct |
2 ms |
3420 KB |
Output is correct |
25 |
Correct |
2 ms |
3420 KB |
Output is correct |
26 |
Correct |
105 ms |
3652 KB |
Output is correct |
27 |
Correct |
17 ms |
3420 KB |
Output is correct |
28 |
Correct |
100 ms |
3672 KB |
Output is correct |
29 |
Correct |
17 ms |
3416 KB |
Output is correct |
30 |
Correct |
105 ms |
3672 KB |
Output is correct |
31 |
Correct |
17 ms |
3672 KB |
Output is correct |
32 |
Correct |
102 ms |
3672 KB |
Output is correct |
33 |
Correct |
17 ms |
3884 KB |
Output is correct |
34 |
Correct |
10 ms |
3672 KB |
Output is correct |
35 |
Correct |
17 ms |
3420 KB |
Output is correct |
36 |
Correct |
102 ms |
3676 KB |
Output is correct |
37 |
Correct |
16 ms |
3420 KB |
Output is correct |
38 |
Correct |
103 ms |
3656 KB |
Output is correct |
39 |
Correct |
16 ms |
3672 KB |
Output is correct |
40 |
Correct |
107 ms |
3660 KB |
Output is correct |
41 |
Correct |
17 ms |
3416 KB |
Output is correct |
42 |
Correct |
104 ms |
3420 KB |
Output is correct |
43 |
Correct |
20 ms |
3420 KB |
Output is correct |
44 |
Correct |
103 ms |
3648 KB |
Output is correct |
45 |
Correct |
19 ms |
3416 KB |
Output is correct |
46 |
Correct |
103 ms |
3420 KB |
Output is correct |
47 |
Correct |
2 ms |
3164 KB |
Output is correct |
48 |
Correct |
61 ms |
3676 KB |
Output is correct |
49 |
Incorrect |
70 ms |
3672 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
341 ms |
4900 KB |
Output is correct |
2 |
Correct |
6 ms |
4188 KB |
Output is correct |
3 |
Correct |
340 ms |
4728 KB |
Output is correct |
4 |
Correct |
6 ms |
4188 KB |
Output is correct |
5 |
Correct |
346 ms |
4912 KB |
Output is correct |
6 |
Correct |
7 ms |
4188 KB |
Output is correct |
7 |
Correct |
342 ms |
4732 KB |
Output is correct |
8 |
Correct |
6 ms |
4184 KB |
Output is correct |
9 |
Correct |
341 ms |
4660 KB |
Output is correct |
10 |
Correct |
6 ms |
4188 KB |
Output is correct |
11 |
Correct |
344 ms |
4652 KB |
Output is correct |
12 |
Correct |
6 ms |
4188 KB |
Output is correct |
13 |
Correct |
328 ms |
4628 KB |
Output is correct |
14 |
Correct |
342 ms |
4692 KB |
Output is correct |
15 |
Correct |
8 ms |
4444 KB |
Output is correct |
16 |
Correct |
355 ms |
4568 KB |
Output is correct |
17 |
Correct |
6 ms |
4188 KB |
Output is correct |
18 |
Correct |
358 ms |
4540 KB |
Output is correct |
19 |
Correct |
6 ms |
4184 KB |
Output is correct |
20 |
Correct |
353 ms |
4592 KB |
Output is correct |
21 |
Correct |
9 ms |
4184 KB |
Output is correct |
22 |
Incorrect |
216 ms |
4744 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3416 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
2 ms |
3420 KB |
Output is correct |
4 |
Correct |
2 ms |
3416 KB |
Output is correct |
5 |
Correct |
2 ms |
3420 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
3 ms |
3420 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
2 ms |
3420 KB |
Output is correct |
12 |
Correct |
2 ms |
3420 KB |
Output is correct |
13 |
Correct |
2 ms |
3420 KB |
Output is correct |
14 |
Correct |
2 ms |
3432 KB |
Output is correct |
15 |
Correct |
2 ms |
3420 KB |
Output is correct |
16 |
Correct |
2 ms |
3428 KB |
Output is correct |
17 |
Correct |
2 ms |
3420 KB |
Output is correct |
18 |
Correct |
3 ms |
3420 KB |
Output is correct |
19 |
Correct |
2 ms |
3384 KB |
Output is correct |
20 |
Correct |
2 ms |
3416 KB |
Output is correct |
21 |
Correct |
1 ms |
2908 KB |
Output is correct |
22 |
Correct |
2 ms |
3420 KB |
Output is correct |
23 |
Correct |
2 ms |
3420 KB |
Output is correct |
24 |
Correct |
2 ms |
3420 KB |
Output is correct |
25 |
Correct |
2 ms |
3420 KB |
Output is correct |
26 |
Correct |
105 ms |
3652 KB |
Output is correct |
27 |
Correct |
17 ms |
3420 KB |
Output is correct |
28 |
Correct |
100 ms |
3672 KB |
Output is correct |
29 |
Correct |
17 ms |
3416 KB |
Output is correct |
30 |
Correct |
105 ms |
3672 KB |
Output is correct |
31 |
Correct |
17 ms |
3672 KB |
Output is correct |
32 |
Correct |
102 ms |
3672 KB |
Output is correct |
33 |
Correct |
17 ms |
3884 KB |
Output is correct |
34 |
Correct |
10 ms |
3672 KB |
Output is correct |
35 |
Correct |
17 ms |
3420 KB |
Output is correct |
36 |
Correct |
102 ms |
3676 KB |
Output is correct |
37 |
Correct |
16 ms |
3420 KB |
Output is correct |
38 |
Correct |
103 ms |
3656 KB |
Output is correct |
39 |
Correct |
16 ms |
3672 KB |
Output is correct |
40 |
Correct |
107 ms |
3660 KB |
Output is correct |
41 |
Correct |
17 ms |
3416 KB |
Output is correct |
42 |
Correct |
104 ms |
3420 KB |
Output is correct |
43 |
Correct |
20 ms |
3420 KB |
Output is correct |
44 |
Correct |
103 ms |
3648 KB |
Output is correct |
45 |
Correct |
19 ms |
3416 KB |
Output is correct |
46 |
Correct |
103 ms |
3420 KB |
Output is correct |
47 |
Correct |
2 ms |
3164 KB |
Output is correct |
48 |
Correct |
61 ms |
3676 KB |
Output is correct |
49 |
Incorrect |
70 ms |
3672 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |