답안 #896307

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
896307 2024-01-01T08:23:09 Z arashMLG Tug of War (BOI15_tug) C++17
100 / 100
1557 ms 10844 KB
#include<bits/stdc++.h>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...) 69
#endif
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;

typedef long long     ll;
typedef pair<int,int> pii;
typedef pair<ll,ll>   pll;

const int M = 3e4 + 23;
const int N =M*2;
const int LOG = 20;
const int ZERO = N*LOG/2;
const ll inf = 1e18;

#define F           first
#define S           second
#define pb          push_back
#define kill(x)     cout<<x<<endl, exit(0);
#define all(x)      x.begin(),x.end()
#define sz(x)       (int)x.size()
#define lc          (v << 1)
#define rc          ((v<<1) |1)

int n,k;
int w[N];
set<pii> G[N];
vector<int> vals;
bitset<N*LOG> dp;
int sum;

void dfs(int v,int sex = 1) {
	if(sz(G[v])) {
		pii u = *G[v].begin();
		G[v].clear();
		G[u.F].erase({v,u.S});
		sum += sex * w[u.S];
		dfs(u.F,-sex);
	}	
}

queue<int> Q;

int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(false);
	cin>>n>>k;
	for(int i=0; i< 2*n ; i ++) {
		int l,r; cin>>l>>r>>w[i]; l--,r--;
		r += n;
		G[l].insert({r,i});
		G[r].insert({l,i});
	}
	for(int i = 0; i<2*n ; i ++) {
		if(!sz(G[i])) kill("NO");
		if(sz(G[i]) == 1) {
			Q.push(i);
		}
	}
	int begsum = 0;
	while(sz(Q)) {
		int v = Q.front(); Q.pop();
		pii u = *G[v].begin();
		G[v].clear();
		G[u.F].erase({v,u.S});
		if(v < n) begsum += w[u.S];
		else begsum -= w[u.S];
		if(sz(G[u.F]) == 1) Q.push(u.F);
	}
	for(int i = 0; i < 2*n; i ++) if(sz(G[i])) {
		sum = 0; dfs(i); vals.pb(abs(sum));
	}
	dp[ZERO+begsum] = 1;
	debug(vals);
	for(int val : vals) {
		dp = (dp << val) | (dp >> val);
	}
	for(int i = 0 ; i < N*LOG; i ++) if(dp[i] && abs(ZERO - i) <= k) kill("YES");
	kill("NO");
	return 0;
}

// Jumpsuit, Jumpsuit cover me!
// Jumpsuit, Jumpsuit cover me!

Compilation message

tug.cpp: In function 'int32_t main()':
tug.cpp:5:20: warning: statement has no effect [-Wunused-value]
    5 | #define debug(...) 69
      |                    ^~
tug.cpp:79:2: note: in expansion of macro 'debug'
   79 |  debug(vals);
      |  ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3676 KB Output is correct
2 Correct 2 ms 3676 KB Output is correct
3 Correct 3 ms 3676 KB Output is correct
4 Correct 3 ms 3676 KB Output is correct
5 Correct 2 ms 3676 KB Output is correct
6 Correct 3 ms 3676 KB Output is correct
7 Correct 2 ms 3676 KB Output is correct
8 Correct 2 ms 3676 KB Output is correct
9 Correct 2 ms 3676 KB Output is correct
10 Correct 3 ms 3724 KB Output is correct
11 Correct 2 ms 3676 KB Output is correct
12 Correct 2 ms 3676 KB Output is correct
13 Correct 2 ms 3676 KB Output is correct
14 Correct 2 ms 3676 KB Output is correct
15 Correct 2 ms 3676 KB Output is correct
16 Correct 2 ms 3676 KB Output is correct
17 Correct 2 ms 3672 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3676 KB Output is correct
22 Correct 2 ms 3676 KB Output is correct
23 Correct 3 ms 3676 KB Output is correct
24 Correct 2 ms 3676 KB Output is correct
25 Correct 2 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3676 KB Output is correct
2 Correct 2 ms 3676 KB Output is correct
3 Correct 3 ms 3676 KB Output is correct
4 Correct 3 ms 3676 KB Output is correct
5 Correct 2 ms 3676 KB Output is correct
6 Correct 3 ms 3676 KB Output is correct
7 Correct 2 ms 3676 KB Output is correct
8 Correct 2 ms 3676 KB Output is correct
9 Correct 2 ms 3676 KB Output is correct
10 Correct 3 ms 3724 KB Output is correct
11 Correct 2 ms 3676 KB Output is correct
12 Correct 2 ms 3676 KB Output is correct
13 Correct 2 ms 3676 KB Output is correct
14 Correct 2 ms 3676 KB Output is correct
15 Correct 2 ms 3676 KB Output is correct
16 Correct 2 ms 3676 KB Output is correct
17 Correct 2 ms 3672 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3676 KB Output is correct
22 Correct 2 ms 3676 KB Output is correct
23 Correct 3 ms 3676 KB Output is correct
24 Correct 2 ms 3676 KB Output is correct
25 Correct 2 ms 3676 KB Output is correct
26 Correct 101 ms 4168 KB Output is correct
27 Correct 16 ms 4184 KB Output is correct
28 Correct 98 ms 4296 KB Output is correct
29 Correct 16 ms 4188 KB Output is correct
30 Correct 98 ms 4188 KB Output is correct
31 Correct 16 ms 4440 KB Output is correct
32 Correct 95 ms 4188 KB Output is correct
33 Correct 17 ms 4188 KB Output is correct
34 Correct 10 ms 4188 KB Output is correct
35 Correct 17 ms 4308 KB Output is correct
36 Correct 100 ms 4300 KB Output is correct
37 Correct 16 ms 4300 KB Output is correct
38 Correct 102 ms 4296 KB Output is correct
39 Correct 17 ms 4300 KB Output is correct
40 Correct 98 ms 4184 KB Output is correct
41 Correct 20 ms 4188 KB Output is correct
42 Correct 98 ms 4304 KB Output is correct
43 Correct 17 ms 4188 KB Output is correct
44 Correct 97 ms 4296 KB Output is correct
45 Correct 19 ms 4188 KB Output is correct
46 Correct 99 ms 4184 KB Output is correct
47 Correct 2 ms 3932 KB Output is correct
48 Correct 51 ms 4188 KB Output is correct
49 Correct 56 ms 4188 KB Output is correct
50 Correct 106 ms 4296 KB Output is correct
51 Correct 107 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 237 ms 5980 KB Output is correct
2 Correct 7 ms 5724 KB Output is correct
3 Correct 234 ms 6136 KB Output is correct
4 Correct 7 ms 5776 KB Output is correct
5 Correct 226 ms 6144 KB Output is correct
6 Correct 7 ms 5724 KB Output is correct
7 Correct 222 ms 5992 KB Output is correct
8 Correct 7 ms 5724 KB Output is correct
9 Correct 222 ms 6088 KB Output is correct
10 Correct 7 ms 5720 KB Output is correct
11 Correct 246 ms 6144 KB Output is correct
12 Correct 7 ms 6076 KB Output is correct
13 Correct 225 ms 6140 KB Output is correct
14 Correct 250 ms 6228 KB Output is correct
15 Correct 7 ms 5724 KB Output is correct
16 Correct 225 ms 6140 KB Output is correct
17 Correct 7 ms 5720 KB Output is correct
18 Correct 238 ms 5980 KB Output is correct
19 Correct 8 ms 5772 KB Output is correct
20 Correct 234 ms 6136 KB Output is correct
21 Correct 8 ms 5720 KB Output is correct
22 Correct 123 ms 5976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3676 KB Output is correct
2 Correct 2 ms 3676 KB Output is correct
3 Correct 3 ms 3676 KB Output is correct
4 Correct 3 ms 3676 KB Output is correct
5 Correct 2 ms 3676 KB Output is correct
6 Correct 3 ms 3676 KB Output is correct
7 Correct 2 ms 3676 KB Output is correct
8 Correct 2 ms 3676 KB Output is correct
9 Correct 2 ms 3676 KB Output is correct
10 Correct 3 ms 3724 KB Output is correct
11 Correct 2 ms 3676 KB Output is correct
12 Correct 2 ms 3676 KB Output is correct
13 Correct 2 ms 3676 KB Output is correct
14 Correct 2 ms 3676 KB Output is correct
15 Correct 2 ms 3676 KB Output is correct
16 Correct 2 ms 3676 KB Output is correct
17 Correct 2 ms 3672 KB Output is correct
18 Correct 2 ms 3676 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3676 KB Output is correct
22 Correct 2 ms 3676 KB Output is correct
23 Correct 3 ms 3676 KB Output is correct
24 Correct 2 ms 3676 KB Output is correct
25 Correct 2 ms 3676 KB Output is correct
26 Correct 101 ms 4168 KB Output is correct
27 Correct 16 ms 4184 KB Output is correct
28 Correct 98 ms 4296 KB Output is correct
29 Correct 16 ms 4188 KB Output is correct
30 Correct 98 ms 4188 KB Output is correct
31 Correct 16 ms 4440 KB Output is correct
32 Correct 95 ms 4188 KB Output is correct
33 Correct 17 ms 4188 KB Output is correct
34 Correct 10 ms 4188 KB Output is correct
35 Correct 17 ms 4308 KB Output is correct
36 Correct 100 ms 4300 KB Output is correct
37 Correct 16 ms 4300 KB Output is correct
38 Correct 102 ms 4296 KB Output is correct
39 Correct 17 ms 4300 KB Output is correct
40 Correct 98 ms 4184 KB Output is correct
41 Correct 20 ms 4188 KB Output is correct
42 Correct 98 ms 4304 KB Output is correct
43 Correct 17 ms 4188 KB Output is correct
44 Correct 97 ms 4296 KB Output is correct
45 Correct 19 ms 4188 KB Output is correct
46 Correct 99 ms 4184 KB Output is correct
47 Correct 2 ms 3932 KB Output is correct
48 Correct 51 ms 4188 KB Output is correct
49 Correct 56 ms 4188 KB Output is correct
50 Correct 106 ms 4296 KB Output is correct
51 Correct 107 ms 4188 KB Output is correct
52 Correct 237 ms 5980 KB Output is correct
53 Correct 7 ms 5724 KB Output is correct
54 Correct 234 ms 6136 KB Output is correct
55 Correct 7 ms 5776 KB Output is correct
56 Correct 226 ms 6144 KB Output is correct
57 Correct 7 ms 5724 KB Output is correct
58 Correct 222 ms 5992 KB Output is correct
59 Correct 7 ms 5724 KB Output is correct
60 Correct 222 ms 6088 KB Output is correct
61 Correct 7 ms 5720 KB Output is correct
62 Correct 246 ms 6144 KB Output is correct
63 Correct 7 ms 6076 KB Output is correct
64 Correct 225 ms 6140 KB Output is correct
65 Correct 250 ms 6228 KB Output is correct
66 Correct 7 ms 5724 KB Output is correct
67 Correct 225 ms 6140 KB Output is correct
68 Correct 7 ms 5720 KB Output is correct
69 Correct 238 ms 5980 KB Output is correct
70 Correct 8 ms 5772 KB Output is correct
71 Correct 234 ms 6136 KB Output is correct
72 Correct 8 ms 5720 KB Output is correct
73 Correct 123 ms 5976 KB Output is correct
74 Correct 1496 ms 10588 KB Output is correct
75 Correct 77 ms 10332 KB Output is correct
76 Correct 1487 ms 10844 KB Output is correct
77 Correct 81 ms 10332 KB Output is correct
78 Correct 1460 ms 10780 KB Output is correct
79 Correct 1478 ms 10788 KB Output is correct
80 Correct 76 ms 10328 KB Output is correct
81 Correct 92 ms 10736 KB Output is correct
82 Correct 1477 ms 10528 KB Output is correct
83 Correct 1436 ms 10784 KB Output is correct
84 Correct 79 ms 10320 KB Output is correct
85 Correct 1489 ms 10780 KB Output is correct
86 Correct 85 ms 10332 KB Output is correct
87 Correct 1471 ms 10784 KB Output is correct
88 Correct 79 ms 10528 KB Output is correct
89 Correct 1488 ms 10784 KB Output is correct
90 Correct 93 ms 10328 KB Output is correct
91 Correct 1443 ms 10796 KB Output is correct
92 Correct 84 ms 10324 KB Output is correct
93 Correct 1464 ms 10840 KB Output is correct
94 Correct 26 ms 10320 KB Output is correct
95 Correct 767 ms 10836 KB Output is correct
96 Correct 797 ms 10688 KB Output is correct
97 Correct 1511 ms 10784 KB Output is correct
98 Correct 1557 ms 10780 KB Output is correct