Submission #658612

# Submission time Handle Problem Language Result Execution time Memory
658612 2022-11-13T19:17:21 Z Shahrad Tug of War (BOI15_tug) C++17
41 / 100
77 ms 6612 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define int ll
#define all(x) x.begin(),x.end()
#define sz size()
#define pb push_back
#define F first
#define S second
#define mk make_pair
#define pii pair<int,int>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

const int N = 1e5 + 5, M = 2e6, M2 = 2 * M;

vector <pii> adj[N];
int s[N], cnt[M2];
bool vis[N];
int ans, wef, few, q;
bitset <M2> bs;

void dfs (int v, int b, int par)
{
	wef++;
	vis[v] = 1;
	few += adj[v].sz;
	for (pii u : adj[v])
	{
		if ((!vis[u.F] || !q) && u.S != par)
		{
			if (vis[u.F])
			{
				q = 1;
				if (!b)
					ans += s[u.S];
				else
					ans -= s[u.S];
				continue;
			}
			if (!b)
				ans += s[u.S];
			else
				ans -= s[u.S];
			dfs (u.F, 1 - b, u.S);
		}
	}
}

void Solve ()
{
	int n, k, l, r;
	cin >> n >> k;
	for (int i = 0; i < 2 * n; i++)
	{
		cin >> l >> r >> s[i];
		r += n;
		l--, r--;
		adj[l].pb (mk (r, i));
		adj[r].pb (mk (l, i));
	}
	for (int i = 0; i < 2 * n; i++)
	{
		if (!vis[i])
		{
			wef = few = ans = q = 0;
			dfs (i, 0, -1);
			if (few != wef * 2)
			{
				cout << "NO" << endl;
				return;
			}
			cnt[abs (ans)]++;
		}
	}
	bs[M] = 1;
	for (int i = 1; i < M2; i++)
	{
		while (cnt[i] > 2)
		{
			cnt[i] -= 2;
			cnt[i * 2]++;
		}
		for (int j = 0; j < cnt[i]; j++)
			bs = (bs << i) | (bs >> i);
	}
	for (int i = M; i <= M + k; i++)
		if (bs[i])
		{
			cout << "YES" << endl;
			return;
		}
	cout << "NO" << endl;
}

int32_t main ()
{
	ios::sync_with_stdio(0), cin.tie (0), cin.tie (0);
	int tt = 1;
//      cin >> tt;
	while (tt--)
		Solve ();
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 5140 KB Output is correct
2 Correct 18 ms 5148 KB Output is correct
3 Correct 18 ms 5140 KB Output is correct
4 Correct 20 ms 5184 KB Output is correct
5 Correct 17 ms 5144 KB Output is correct
6 Correct 17 ms 5156 KB Output is correct
7 Correct 18 ms 5172 KB Output is correct
8 Correct 17 ms 5144 KB Output is correct
9 Correct 17 ms 5140 KB Output is correct
10 Correct 18 ms 5304 KB Output is correct
11 Correct 17 ms 5076 KB Output is correct
12 Correct 17 ms 5136 KB Output is correct
13 Correct 18 ms 5140 KB Output is correct
14 Correct 18 ms 5076 KB Output is correct
15 Correct 23 ms 5132 KB Output is correct
16 Correct 20 ms 5168 KB Output is correct
17 Correct 17 ms 5168 KB Output is correct
18 Correct 17 ms 5152 KB Output is correct
19 Correct 17 ms 5184 KB Output is correct
20 Correct 18 ms 5152 KB Output is correct
21 Correct 2 ms 4564 KB Output is correct
22 Correct 20 ms 5148 KB Output is correct
23 Correct 16 ms 5148 KB Output is correct
24 Correct 18 ms 5184 KB Output is correct
25 Correct 17 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 5140 KB Output is correct
2 Correct 18 ms 5148 KB Output is correct
3 Correct 18 ms 5140 KB Output is correct
4 Correct 20 ms 5184 KB Output is correct
5 Correct 17 ms 5144 KB Output is correct
6 Correct 17 ms 5156 KB Output is correct
7 Correct 18 ms 5172 KB Output is correct
8 Correct 17 ms 5144 KB Output is correct
9 Correct 17 ms 5140 KB Output is correct
10 Correct 18 ms 5304 KB Output is correct
11 Correct 17 ms 5076 KB Output is correct
12 Correct 17 ms 5136 KB Output is correct
13 Correct 18 ms 5140 KB Output is correct
14 Correct 18 ms 5076 KB Output is correct
15 Correct 23 ms 5132 KB Output is correct
16 Correct 20 ms 5168 KB Output is correct
17 Correct 17 ms 5168 KB Output is correct
18 Correct 17 ms 5152 KB Output is correct
19 Correct 17 ms 5184 KB Output is correct
20 Correct 18 ms 5152 KB Output is correct
21 Correct 2 ms 4564 KB Output is correct
22 Correct 20 ms 5148 KB Output is correct
23 Correct 16 ms 5148 KB Output is correct
24 Correct 18 ms 5184 KB Output is correct
25 Correct 17 ms 5144 KB Output is correct
26 Correct 40 ms 5520 KB Output is correct
27 Correct 71 ms 5440 KB Output is correct
28 Correct 33 ms 5404 KB Output is correct
29 Correct 61 ms 5428 KB Output is correct
30 Correct 34 ms 5440 KB Output is correct
31 Correct 63 ms 5452 KB Output is correct
32 Correct 33 ms 5440 KB Output is correct
33 Correct 65 ms 5552 KB Output is correct
34 Correct 23 ms 5460 KB Output is correct
35 Correct 62 ms 5436 KB Output is correct
36 Correct 35 ms 5444 KB Output is correct
37 Correct 77 ms 5476 KB Output is correct
38 Correct 36 ms 5452 KB Output is correct
39 Correct 69 ms 5408 KB Output is correct
40 Correct 32 ms 5404 KB Output is correct
41 Correct 63 ms 5428 KB Output is correct
42 Correct 34 ms 5444 KB Output is correct
43 Correct 71 ms 5424 KB Output is correct
44 Correct 34 ms 5436 KB Output is correct
45 Correct 68 ms 5440 KB Output is correct
46 Correct 37 ms 5436 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 48 ms 5440 KB Output is correct
49 Incorrect 49 ms 5408 KB Output isn't correct
50 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 6044 KB Output is correct
2 Correct 9 ms 6100 KB Output is correct
3 Correct 22 ms 6092 KB Output is correct
4 Correct 9 ms 6048 KB Output is correct
5 Correct 23 ms 6072 KB Output is correct
6 Correct 9 ms 6072 KB Output is correct
7 Correct 24 ms 6076 KB Output is correct
8 Correct 9 ms 6076 KB Output is correct
9 Correct 25 ms 6100 KB Output is correct
10 Correct 9 ms 6100 KB Output is correct
11 Correct 28 ms 6080 KB Output is correct
12 Correct 10 ms 6056 KB Output is correct
13 Correct 23 ms 6092 KB Output is correct
14 Correct 23 ms 6092 KB Output is correct
15 Correct 9 ms 6076 KB Output is correct
16 Correct 25 ms 6100 KB Output is correct
17 Correct 13 ms 6064 KB Output is correct
18 Correct 23 ms 6088 KB Output is correct
19 Correct 9 ms 6100 KB Output is correct
20 Correct 22 ms 6116 KB Output is correct
21 Correct 9 ms 6200 KB Output is correct
22 Correct 28 ms 6612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 5140 KB Output is correct
2 Correct 18 ms 5148 KB Output is correct
3 Correct 18 ms 5140 KB Output is correct
4 Correct 20 ms 5184 KB Output is correct
5 Correct 17 ms 5144 KB Output is correct
6 Correct 17 ms 5156 KB Output is correct
7 Correct 18 ms 5172 KB Output is correct
8 Correct 17 ms 5144 KB Output is correct
9 Correct 17 ms 5140 KB Output is correct
10 Correct 18 ms 5304 KB Output is correct
11 Correct 17 ms 5076 KB Output is correct
12 Correct 17 ms 5136 KB Output is correct
13 Correct 18 ms 5140 KB Output is correct
14 Correct 18 ms 5076 KB Output is correct
15 Correct 23 ms 5132 KB Output is correct
16 Correct 20 ms 5168 KB Output is correct
17 Correct 17 ms 5168 KB Output is correct
18 Correct 17 ms 5152 KB Output is correct
19 Correct 17 ms 5184 KB Output is correct
20 Correct 18 ms 5152 KB Output is correct
21 Correct 2 ms 4564 KB Output is correct
22 Correct 20 ms 5148 KB Output is correct
23 Correct 16 ms 5148 KB Output is correct
24 Correct 18 ms 5184 KB Output is correct
25 Correct 17 ms 5144 KB Output is correct
26 Correct 40 ms 5520 KB Output is correct
27 Correct 71 ms 5440 KB Output is correct
28 Correct 33 ms 5404 KB Output is correct
29 Correct 61 ms 5428 KB Output is correct
30 Correct 34 ms 5440 KB Output is correct
31 Correct 63 ms 5452 KB Output is correct
32 Correct 33 ms 5440 KB Output is correct
33 Correct 65 ms 5552 KB Output is correct
34 Correct 23 ms 5460 KB Output is correct
35 Correct 62 ms 5436 KB Output is correct
36 Correct 35 ms 5444 KB Output is correct
37 Correct 77 ms 5476 KB Output is correct
38 Correct 36 ms 5452 KB Output is correct
39 Correct 69 ms 5408 KB Output is correct
40 Correct 32 ms 5404 KB Output is correct
41 Correct 63 ms 5428 KB Output is correct
42 Correct 34 ms 5444 KB Output is correct
43 Correct 71 ms 5424 KB Output is correct
44 Correct 34 ms 5436 KB Output is correct
45 Correct 68 ms 5440 KB Output is correct
46 Correct 37 ms 5436 KB Output is correct
47 Correct 3 ms 4948 KB Output is correct
48 Correct 48 ms 5440 KB Output is correct
49 Incorrect 49 ms 5408 KB Output isn't correct
50 Halted 0 ms 0 KB -