답안 #76371

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76371 2018-09-13T08:14:46 Z tmwilliamlin168 Tug of War (BOI15_tug) C++14
100 / 100
2334 ms 30048 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN=6e4;
int n, k, l[mxN], r[mxN], s[mxN], dp0;
set<int> pc[mxN];
bitset<20*mxN+1> dp;
queue<int> qu;
vector<int> vc;

void fk() {
	cout << "NO";
	exit(0);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	n*=2;
	for(int i=0; i<n; ++i) {
		cin >> l[i] >> r[i] >> s[i], --l[i], r[i]+=n/2-1;
		pc[l[i]].insert(i);
		pc[r[i]].insert(i);
	}
	for(int i=0; i<n; ++i) {
		if(!pc[i].size())
			fk();
		else if(pc[i].size()==1)
			qu.push(i);
	}
	dp0=10*n;
	while(qu.size()) {
		int u=qu.front();
		if(!pc[u].size())
			fk();
		qu.pop();
		int a=*pc[u].begin(), v=u^l[a]^r[a];
		dp0+=u<n/2?s[a]:-s[a];
		pc[v].erase(a);
		if(pc[v].size()==1)
			qu.push(v);
	}
	for(int i=0; i<n; ++i) {
		if(pc[i].size()<2)
			continue;
		int c=0;
		for(int j=i; pc[j].size(); ) {
			int a=*pc[j].begin();
			c+=j<n/2?s[a]:-s[a];
			pc[l[a]].erase(a);
			pc[r[a]].erase(a);
			j^=l[a]^r[a];
		}
		c=abs(c);
		dp0-=c;
		vc.push_back(2*c);
	}
	dp[dp0]=1;
	for(int c : vc)
		dp|=dp<<c;
	bool ok=0;
	for(int i=10*n-k; i<=10*n+k&&!ok; ++i)
		ok=dp[i];
	if(!ok)
		fk();
	cout << "YES";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3576 KB Output is correct
2 Correct 6 ms 3708 KB Output is correct
3 Correct 5 ms 3708 KB Output is correct
4 Correct 6 ms 3784 KB Output is correct
5 Correct 5 ms 3844 KB Output is correct
6 Correct 5 ms 3920 KB Output is correct
7 Correct 5 ms 3920 KB Output is correct
8 Correct 5 ms 3920 KB Output is correct
9 Correct 5 ms 3920 KB Output is correct
10 Correct 6 ms 3920 KB Output is correct
11 Correct 5 ms 3920 KB Output is correct
12 Correct 5 ms 3920 KB Output is correct
13 Correct 5 ms 3920 KB Output is correct
14 Correct 5 ms 3920 KB Output is correct
15 Correct 5 ms 3920 KB Output is correct
16 Correct 5 ms 3920 KB Output is correct
17 Correct 5 ms 3920 KB Output is correct
18 Correct 5 ms 3920 KB Output is correct
19 Correct 5 ms 3920 KB Output is correct
20 Correct 5 ms 3920 KB Output is correct
21 Correct 4 ms 3920 KB Output is correct
22 Correct 5 ms 3920 KB Output is correct
23 Correct 5 ms 3920 KB Output is correct
24 Correct 5 ms 3920 KB Output is correct
25 Correct 5 ms 3920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3576 KB Output is correct
2 Correct 6 ms 3708 KB Output is correct
3 Correct 5 ms 3708 KB Output is correct
4 Correct 6 ms 3784 KB Output is correct
5 Correct 5 ms 3844 KB Output is correct
6 Correct 5 ms 3920 KB Output is correct
7 Correct 5 ms 3920 KB Output is correct
8 Correct 5 ms 3920 KB Output is correct
9 Correct 5 ms 3920 KB Output is correct
10 Correct 6 ms 3920 KB Output is correct
11 Correct 5 ms 3920 KB Output is correct
12 Correct 5 ms 3920 KB Output is correct
13 Correct 5 ms 3920 KB Output is correct
14 Correct 5 ms 3920 KB Output is correct
15 Correct 5 ms 3920 KB Output is correct
16 Correct 5 ms 3920 KB Output is correct
17 Correct 5 ms 3920 KB Output is correct
18 Correct 5 ms 3920 KB Output is correct
19 Correct 5 ms 3920 KB Output is correct
20 Correct 5 ms 3920 KB Output is correct
21 Correct 4 ms 3920 KB Output is correct
22 Correct 5 ms 3920 KB Output is correct
23 Correct 5 ms 3920 KB Output is correct
24 Correct 5 ms 3920 KB Output is correct
25 Correct 5 ms 3920 KB Output is correct
26 Correct 154 ms 4320 KB Output is correct
27 Correct 27 ms 4320 KB Output is correct
28 Correct 162 ms 4320 KB Output is correct
29 Correct 27 ms 4320 KB Output is correct
30 Correct 154 ms 4320 KB Output is correct
31 Correct 27 ms 4320 KB Output is correct
32 Correct 158 ms 4320 KB Output is correct
33 Correct 27 ms 4320 KB Output is correct
34 Correct 19 ms 4320 KB Output is correct
35 Correct 27 ms 4320 KB Output is correct
36 Correct 161 ms 4320 KB Output is correct
37 Correct 27 ms 4320 KB Output is correct
38 Correct 177 ms 4320 KB Output is correct
39 Correct 29 ms 4320 KB Output is correct
40 Correct 153 ms 4320 KB Output is correct
41 Correct 27 ms 4320 KB Output is correct
42 Correct 155 ms 4320 KB Output is correct
43 Correct 27 ms 4320 KB Output is correct
44 Correct 149 ms 4320 KB Output is correct
45 Correct 27 ms 4320 KB Output is correct
46 Correct 155 ms 4320 KB Output is correct
47 Correct 6 ms 4320 KB Output is correct
48 Correct 114 ms 4320 KB Output is correct
49 Correct 77 ms 4320 KB Output is correct
50 Correct 156 ms 4320 KB Output is correct
51 Correct 153 ms 4332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 461 ms 6012 KB Output is correct
2 Correct 16 ms 6012 KB Output is correct
3 Correct 461 ms 6016 KB Output is correct
4 Correct 17 ms 6016 KB Output is correct
5 Correct 460 ms 6016 KB Output is correct
6 Correct 16 ms 6016 KB Output is correct
7 Correct 443 ms 6016 KB Output is correct
8 Correct 19 ms 6016 KB Output is correct
9 Correct 495 ms 6016 KB Output is correct
10 Correct 16 ms 6016 KB Output is correct
11 Correct 448 ms 6016 KB Output is correct
12 Correct 16 ms 6016 KB Output is correct
13 Correct 454 ms 6016 KB Output is correct
14 Correct 476 ms 6016 KB Output is correct
15 Correct 17 ms 6016 KB Output is correct
16 Correct 476 ms 6016 KB Output is correct
17 Correct 21 ms 6016 KB Output is correct
18 Correct 455 ms 6140 KB Output is correct
19 Correct 17 ms 6140 KB Output is correct
20 Correct 452 ms 6140 KB Output is correct
21 Correct 17 ms 6140 KB Output is correct
22 Correct 244 ms 6140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3576 KB Output is correct
2 Correct 6 ms 3708 KB Output is correct
3 Correct 5 ms 3708 KB Output is correct
4 Correct 6 ms 3784 KB Output is correct
5 Correct 5 ms 3844 KB Output is correct
6 Correct 5 ms 3920 KB Output is correct
7 Correct 5 ms 3920 KB Output is correct
8 Correct 5 ms 3920 KB Output is correct
9 Correct 5 ms 3920 KB Output is correct
10 Correct 6 ms 3920 KB Output is correct
11 Correct 5 ms 3920 KB Output is correct
12 Correct 5 ms 3920 KB Output is correct
13 Correct 5 ms 3920 KB Output is correct
14 Correct 5 ms 3920 KB Output is correct
15 Correct 5 ms 3920 KB Output is correct
16 Correct 5 ms 3920 KB Output is correct
17 Correct 5 ms 3920 KB Output is correct
18 Correct 5 ms 3920 KB Output is correct
19 Correct 5 ms 3920 KB Output is correct
20 Correct 5 ms 3920 KB Output is correct
21 Correct 4 ms 3920 KB Output is correct
22 Correct 5 ms 3920 KB Output is correct
23 Correct 5 ms 3920 KB Output is correct
24 Correct 5 ms 3920 KB Output is correct
25 Correct 5 ms 3920 KB Output is correct
26 Correct 154 ms 4320 KB Output is correct
27 Correct 27 ms 4320 KB Output is correct
28 Correct 162 ms 4320 KB Output is correct
29 Correct 27 ms 4320 KB Output is correct
30 Correct 154 ms 4320 KB Output is correct
31 Correct 27 ms 4320 KB Output is correct
32 Correct 158 ms 4320 KB Output is correct
33 Correct 27 ms 4320 KB Output is correct
34 Correct 19 ms 4320 KB Output is correct
35 Correct 27 ms 4320 KB Output is correct
36 Correct 161 ms 4320 KB Output is correct
37 Correct 27 ms 4320 KB Output is correct
38 Correct 177 ms 4320 KB Output is correct
39 Correct 29 ms 4320 KB Output is correct
40 Correct 153 ms 4320 KB Output is correct
41 Correct 27 ms 4320 KB Output is correct
42 Correct 155 ms 4320 KB Output is correct
43 Correct 27 ms 4320 KB Output is correct
44 Correct 149 ms 4320 KB Output is correct
45 Correct 27 ms 4320 KB Output is correct
46 Correct 155 ms 4320 KB Output is correct
47 Correct 6 ms 4320 KB Output is correct
48 Correct 114 ms 4320 KB Output is correct
49 Correct 77 ms 4320 KB Output is correct
50 Correct 156 ms 4320 KB Output is correct
51 Correct 153 ms 4332 KB Output is correct
52 Correct 461 ms 6012 KB Output is correct
53 Correct 16 ms 6012 KB Output is correct
54 Correct 461 ms 6016 KB Output is correct
55 Correct 17 ms 6016 KB Output is correct
56 Correct 460 ms 6016 KB Output is correct
57 Correct 16 ms 6016 KB Output is correct
58 Correct 443 ms 6016 KB Output is correct
59 Correct 19 ms 6016 KB Output is correct
60 Correct 495 ms 6016 KB Output is correct
61 Correct 16 ms 6016 KB Output is correct
62 Correct 448 ms 6016 KB Output is correct
63 Correct 16 ms 6016 KB Output is correct
64 Correct 454 ms 6016 KB Output is correct
65 Correct 476 ms 6016 KB Output is correct
66 Correct 17 ms 6016 KB Output is correct
67 Correct 476 ms 6016 KB Output is correct
68 Correct 21 ms 6016 KB Output is correct
69 Correct 455 ms 6140 KB Output is correct
70 Correct 17 ms 6140 KB Output is correct
71 Correct 452 ms 6140 KB Output is correct
72 Correct 17 ms 6140 KB Output is correct
73 Correct 244 ms 6140 KB Output is correct
74 Correct 2334 ms 10492 KB Output is correct
75 Correct 179 ms 11004 KB Output is correct
76 Correct 2218 ms 12116 KB Output is correct
77 Correct 149 ms 12688 KB Output is correct
78 Correct 2226 ms 13744 KB Output is correct
79 Correct 2267 ms 14504 KB Output is correct
80 Correct 154 ms 15136 KB Output is correct
81 Correct 146 ms 16064 KB Output is correct
82 Correct 2202 ms 16748 KB Output is correct
83 Correct 2221 ms 17768 KB Output is correct
84 Correct 134 ms 18372 KB Output is correct
85 Correct 2180 ms 19384 KB Output is correct
86 Correct 146 ms 20020 KB Output is correct
87 Correct 2241 ms 21156 KB Output is correct
88 Correct 151 ms 21704 KB Output is correct
89 Correct 2217 ms 22692 KB Output is correct
90 Correct 147 ms 23324 KB Output is correct
91 Correct 2256 ms 24388 KB Output is correct
92 Correct 146 ms 24944 KB Output is correct
93 Correct 2230 ms 25952 KB Output is correct
94 Correct 59 ms 26180 KB Output is correct
95 Correct 1133 ms 27644 KB Output is correct
96 Correct 1152 ms 28408 KB Output is correct
97 Correct 2231 ms 29240 KB Output is correct
98 Correct 2279 ms 30048 KB Output is correct