답안 #681926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681926 2023-01-14T22:22:45 Z MilosMilutinovic Tug of War (BOI15_tug) C++14
23 / 100
222 ms 5080 KB
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
using namespace std;

typedef long long ll;

const int N = 30333;
int n, k;
int l[2 * N];
int r[2 * N];
int s[2 * N];
vector<int> g[4 * N];
int ver;
int pos;
bool was[4 * N];
ll sum[2];

void addEdge(int v, int u) {
	g[v].push_back(u);
	g[u].push_back(v);
}

void dfs(int v) {
	if (v < 2 * n) {
		sum[ver & 1] += s[v];
		ver++;
	} else pos++;
	was[v] = true;
	for (int u : g[v])
		if (!was[u])
			dfs(u);
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &k);
	assert(k >= 0);
	for (int i = 0; i < 2 * n; i++) {
		scanf("%d%d%d", &l[i], &r[i], &s[i]);
		--l[i];--r[i];
		addEdge(i, 2 * n + l[i]);
		addEdge(i, 3 * n + r[i]);
	}
	vector<int> diff;
	for (int i = 0; i < 2 * n; i++) if (!was[i]) {
		ver = 0;
		pos = 0;
		sum[0] = 0;
		sum[1] = 0;
		dfs(i);
		diff.push_back(sum[0] - sum[1]);
		if (ver > pos) {
			printf("NO\n");
			return 0;
		}
	}
	bitset<20 * N + 1> dp;
	dp[0] = 1;
	for (int x : diff) {
		x = abs(x);
		dp = ((dp >> x) | (dp << x));
	}
	bool ok = false;
	for (int i = 0; i <= k; i++)
		if (dp[i])
			ok = true;
	if (ok)
		printf("YES\n");
	else
		printf("NO\n");

	return 0;
}

Compilation message

tug.cpp: In function 'int main()':
tug.cpp:57:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
tug.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   scanf("%d%d%d", &l[i], &r[i], &s[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 3 ms 3420 KB Output is correct
4 Correct 3 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Incorrect 2 ms 3460 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 3 ms 3420 KB Output is correct
4 Correct 3 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Incorrect 2 ms 3460 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 5076 KB Output is correct
2 Correct 10 ms 4948 KB Output is correct
3 Correct 193 ms 5064 KB Output is correct
4 Correct 14 ms 4948 KB Output is correct
5 Correct 182 ms 5080 KB Output is correct
6 Correct 10 ms 4948 KB Output is correct
7 Correct 177 ms 5076 KB Output is correct
8 Correct 11 ms 4840 KB Output is correct
9 Correct 182 ms 5080 KB Output is correct
10 Correct 11 ms 4964 KB Output is correct
11 Correct 183 ms 5076 KB Output is correct
12 Correct 11 ms 4968 KB Output is correct
13 Correct 178 ms 5076 KB Output is correct
14 Correct 179 ms 5076 KB Output is correct
15 Correct 10 ms 4840 KB Output is correct
16 Correct 175 ms 5044 KB Output is correct
17 Correct 10 ms 4948 KB Output is correct
18 Correct 222 ms 5076 KB Output is correct
19 Correct 14 ms 4892 KB Output is correct
20 Correct 172 ms 5076 KB Output is correct
21 Correct 11 ms 5008 KB Output is correct
22 Correct 135 ms 5028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 3 ms 3420 KB Output is correct
4 Correct 3 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Incorrect 2 ms 3460 KB Output isn't correct
8 Halted 0 ms 0 KB -