답안 #772884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
772884 2023-07-04T12:20:15 Z Ahmed57 Tug of War (BOI15_tug) C++17
100 / 100
1061 ms 10960 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 2 ms 3540 KB Output is correct
2 Correct 2 ms 3568 KB Output is correct
3 Correct 2 ms 3564 KB Output is correct
4 Correct 2 ms 3540 KB Output is correct
5 Correct 2 ms 3572 KB Output is correct
6 Correct 2 ms 3564 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 2 ms 3576 KB Output is correct
10 Correct 2 ms 3540 KB Output is correct
11 Correct 2 ms 3540 KB Output is correct
12 Correct 2 ms 3540 KB Output is correct
13 Correct 2 ms 3540 KB Output is correct
14 Correct 2 ms 3540 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 3 ms 3568 KB Output is correct
17 Correct 2 ms 3540 KB Output is correct
18 Correct 2 ms 3540 KB Output is correct
19 Correct 3 ms 3540 KB Output is correct
20 Correct 2 ms 3572 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3540 KB Output is correct
23 Correct 2 ms 3568 KB Output is correct
24 Correct 2 ms 3540 KB Output is correct
25 Correct 2 ms 3540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3540 KB Output is correct
2 Correct 2 ms 3568 KB Output is correct
3 Correct 2 ms 3564 KB Output is correct
4 Correct 2 ms 3540 KB Output is correct
5 Correct 2 ms 3572 KB Output is correct
6 Correct 2 ms 3564 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 2 ms 3576 KB Output is correct
10 Correct 2 ms 3540 KB Output is correct
11 Correct 2 ms 3540 KB Output is correct
12 Correct 2 ms 3540 KB Output is correct
13 Correct 2 ms 3540 KB Output is correct
14 Correct 2 ms 3540 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 3 ms 3568 KB Output is correct
17 Correct 2 ms 3540 KB Output is correct
18 Correct 2 ms 3540 KB Output is correct
19 Correct 3 ms 3540 KB Output is correct
20 Correct 2 ms 3572 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3540 KB Output is correct
23 Correct 2 ms 3568 KB Output is correct
24 Correct 2 ms 3540 KB Output is correct
25 Correct 2 ms 3540 KB Output is correct
26 Correct 66 ms 4060 KB Output is correct
27 Correct 12 ms 4052 KB Output is correct
28 Correct 65 ms 4064 KB Output is correct
29 Correct 12 ms 4064 KB Output is correct
30 Correct 66 ms 4060 KB Output is correct
31 Correct 14 ms 4060 KB Output is correct
32 Correct 64 ms 4060 KB Output is correct
33 Correct 11 ms 3960 KB Output is correct
34 Correct 7 ms 3952 KB Output is correct
35 Correct 12 ms 4052 KB Output is correct
36 Correct 68 ms 4060 KB Output is correct
37 Correct 14 ms 4056 KB Output is correct
38 Correct 65 ms 4052 KB Output is correct
39 Correct 12 ms 4064 KB Output is correct
40 Correct 65 ms 4052 KB Output is correct
41 Correct 11 ms 3960 KB Output is correct
42 Correct 65 ms 4052 KB Output is correct
43 Correct 12 ms 3960 KB Output is correct
44 Correct 65 ms 4068 KB Output is correct
45 Correct 12 ms 4064 KB Output is correct
46 Correct 78 ms 4064 KB Output is correct
47 Correct 3 ms 3796 KB Output is correct
48 Correct 36 ms 3968 KB Output is correct
49 Correct 34 ms 4052 KB Output is correct
50 Correct 67 ms 4064 KB Output is correct
51 Correct 67 ms 4072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 6024 KB Output is correct
2 Correct 10 ms 5716 KB Output is correct
3 Correct 153 ms 6040 KB Output is correct
4 Correct 8 ms 5716 KB Output is correct
5 Correct 170 ms 6028 KB Output is correct
6 Correct 7 ms 5716 KB Output is correct
7 Correct 172 ms 6020 KB Output is correct
8 Correct 9 ms 5756 KB Output is correct
9 Correct 155 ms 6024 KB Output is correct
10 Correct 8 ms 5716 KB Output is correct
11 Correct 150 ms 5924 KB Output is correct
12 Correct 8 ms 5716 KB Output is correct
13 Correct 153 ms 5984 KB Output is correct
14 Correct 157 ms 5972 KB Output is correct
15 Correct 8 ms 5716 KB Output is correct
16 Correct 154 ms 6016 KB Output is correct
17 Correct 8 ms 5716 KB Output is correct
18 Correct 156 ms 6028 KB Output is correct
19 Correct 8 ms 5716 KB Output is correct
20 Correct 158 ms 6040 KB Output is correct
21 Correct 8 ms 5716 KB Output is correct
22 Correct 84 ms 5996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3540 KB Output is correct
2 Correct 2 ms 3568 KB Output is correct
3 Correct 2 ms 3564 KB Output is correct
4 Correct 2 ms 3540 KB Output is correct
5 Correct 2 ms 3572 KB Output is correct
6 Correct 2 ms 3564 KB Output is correct
7 Correct 2 ms 3540 KB Output is correct
8 Correct 2 ms 3540 KB Output is correct
9 Correct 2 ms 3576 KB Output is correct
10 Correct 2 ms 3540 KB Output is correct
11 Correct 2 ms 3540 KB Output is correct
12 Correct 2 ms 3540 KB Output is correct
13 Correct 2 ms 3540 KB Output is correct
14 Correct 2 ms 3540 KB Output is correct
15 Correct 2 ms 3540 KB Output is correct
16 Correct 3 ms 3568 KB Output is correct
17 Correct 2 ms 3540 KB Output is correct
18 Correct 2 ms 3540 KB Output is correct
19 Correct 3 ms 3540 KB Output is correct
20 Correct 2 ms 3572 KB Output is correct
21 Correct 2 ms 3412 KB Output is correct
22 Correct 2 ms 3540 KB Output is correct
23 Correct 2 ms 3568 KB Output is correct
24 Correct 2 ms 3540 KB Output is correct
25 Correct 2 ms 3540 KB Output is correct
26 Correct 66 ms 4060 KB Output is correct
27 Correct 12 ms 4052 KB Output is correct
28 Correct 65 ms 4064 KB Output is correct
29 Correct 12 ms 4064 KB Output is correct
30 Correct 66 ms 4060 KB Output is correct
31 Correct 14 ms 4060 KB Output is correct
32 Correct 64 ms 4060 KB Output is correct
33 Correct 11 ms 3960 KB Output is correct
34 Correct 7 ms 3952 KB Output is correct
35 Correct 12 ms 4052 KB Output is correct
36 Correct 68 ms 4060 KB Output is correct
37 Correct 14 ms 4056 KB Output is correct
38 Correct 65 ms 4052 KB Output is correct
39 Correct 12 ms 4064 KB Output is correct
40 Correct 65 ms 4052 KB Output is correct
41 Correct 11 ms 3960 KB Output is correct
42 Correct 65 ms 4052 KB Output is correct
43 Correct 12 ms 3960 KB Output is correct
44 Correct 65 ms 4068 KB Output is correct
45 Correct 12 ms 4064 KB Output is correct
46 Correct 78 ms 4064 KB Output is correct
47 Correct 3 ms 3796 KB Output is correct
48 Correct 36 ms 3968 KB Output is correct
49 Correct 34 ms 4052 KB Output is correct
50 Correct 67 ms 4064 KB Output is correct
51 Correct 67 ms 4072 KB Output is correct
52 Correct 159 ms 6024 KB Output is correct
53 Correct 10 ms 5716 KB Output is correct
54 Correct 153 ms 6040 KB Output is correct
55 Correct 8 ms 5716 KB Output is correct
56 Correct 170 ms 6028 KB Output is correct
57 Correct 7 ms 5716 KB Output is correct
58 Correct 172 ms 6020 KB Output is correct
59 Correct 9 ms 5756 KB Output is correct
60 Correct 155 ms 6024 KB Output is correct
61 Correct 8 ms 5716 KB Output is correct
62 Correct 150 ms 5924 KB Output is correct
63 Correct 8 ms 5716 KB Output is correct
64 Correct 153 ms 5984 KB Output is correct
65 Correct 157 ms 5972 KB Output is correct
66 Correct 8 ms 5716 KB Output is correct
67 Correct 154 ms 6016 KB Output is correct
68 Correct 8 ms 5716 KB Output is correct
69 Correct 156 ms 6028 KB Output is correct
70 Correct 8 ms 5716 KB Output is correct
71 Correct 158 ms 6040 KB Output is correct
72 Correct 8 ms 5716 KB Output is correct
73 Correct 84 ms 5996 KB Output is correct
74 Correct 977 ms 10904 KB Output is correct
75 Correct 68 ms 10700 KB Output is correct
76 Correct 969 ms 10868 KB Output is correct
77 Correct 73 ms 10752 KB Output is correct
78 Correct 1016 ms 10868 KB Output is correct
79 Correct 972 ms 10888 KB Output is correct
80 Correct 73 ms 10688 KB Output is correct
81 Correct 88 ms 10612 KB Output is correct
82 Correct 1014 ms 10712 KB Output is correct
83 Correct 967 ms 10960 KB Output is correct
84 Correct 84 ms 10708 KB Output is correct
85 Correct 988 ms 10856 KB Output is correct
86 Correct 70 ms 10720 KB Output is correct
87 Correct 980 ms 10924 KB Output is correct
88 Correct 63 ms 10624 KB Output is correct
89 Correct 1002 ms 10952 KB Output is correct
90 Correct 66 ms 10712 KB Output is correct
91 Correct 992 ms 10956 KB Output is correct
92 Correct 66 ms 10716 KB Output is correct
93 Correct 1057 ms 10872 KB Output is correct
94 Correct 33 ms 10444 KB Output is correct
95 Correct 549 ms 10868 KB Output is correct
96 Correct 501 ms 10880 KB Output is correct
97 Correct 1061 ms 10952 KB Output is correct
98 Correct 1004 ms 10940 KB Output is correct