답안 #1020743

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1020743 2024-07-12T09:09:52 Z owoovo Tug of War (BOI15_tug) C++17
100 / 100
1765 ms 6664 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("popcnt,avx2")
#define ll long long
#define F first 
#define S second 
using namespace std;
bitset<1200010> bs;
int n,k,sum,d[60010],use[60010],useedge[60010];
vector<pair<pair<int,int>,int>> edge;
vector<int> e[60010];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    bs[0]=1;
    cin>>n>>k;
    for(int i=0;i<2*n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        sum+=c;
        edge.push_back({{a,b+n},c});
        e[a].push_back(i);
        e[b+n].push_back(i);
        d[a]++;
        d[b+n]++;
    }
    queue<int> q;
    for(int i=1;i<=2*n;i++){
        if(d[i]==1)q.push(i);
    }
    while(!q.empty()){
        int now=q.front();
        q.pop();
        for(auto x:e[now]){
            if(useedge[x]!=0)continue;
            useedge[x]=1;
            if(now<=n){
                bs<<=edge[x].S;
            }
            use[now]=1;
            d[edge[x].F.F]--;
            if(d[edge[x].F.F]==1)q.push(edge[x].F.F);
            d[edge[x].F.S]--;
            if(d[edge[x].F.S]==1)q.push(edge[x].F.S);
        }
    }
    for(int i=1;i<=2*n;i++){
        if(use[i]==0&&d[i]==0){
            cout<<"NO\n";
            return 0;
        }
    }
    for(int i=1;i<=2*n;i++){
        if(use[i]==1)continue;
        ll val[2]={0,0},bt=0,cnt=0;
        int now=i;
        while(use[now]==0){
            for(auto x:e[now]){
                if(useedge[x])continue;
                useedge[x]=1;
                use[now]=1;
                val[bt]+=edge[x].S;
                bt^=1;
                now=now^edge[x].F.F^edge[x].F.S;
                break;
            }
        }
        bs=(bs<<val[0])|(bs<<val[1]);
    }
    for(int i=0;i<=sum;i++){
        if(abs(sum-2*i)<=k&bs[i]){
            cout<<"YES\n";
            return 0;
        }
    }
    cout<<"NO\n";
    return 0;
}

Compilation message

tug.cpp: In function 'int main()':
tug.cpp:55:30: warning: unused variable 'cnt' [-Wunused-variable]
   55 |         ll val[2]={0,0},bt=0,cnt=0;
      |                              ^~~
tug.cpp:71:24: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   71 |         if(abs(sum-2*i)<=k&bs[i]){
      |            ~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 2 ms 2392 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2464 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2392 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 2 ms 2392 KB Output is correct
19 Correct 2 ms 2392 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 2 ms 2392 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 3 ms 2404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 2 ms 2392 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2464 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2392 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 2 ms 2392 KB Output is correct
19 Correct 2 ms 2392 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 2 ms 2392 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 3 ms 2404 KB Output is correct
26 Correct 103 ms 2648 KB Output is correct
27 Correct 27 ms 2648 KB Output is correct
28 Correct 104 ms 2712 KB Output is correct
29 Correct 15 ms 2732 KB Output is correct
30 Correct 109 ms 2652 KB Output is correct
31 Correct 16 ms 2652 KB Output is correct
32 Correct 122 ms 2652 KB Output is correct
33 Correct 16 ms 2652 KB Output is correct
34 Correct 9 ms 2652 KB Output is correct
35 Correct 21 ms 2648 KB Output is correct
36 Correct 115 ms 2732 KB Output is correct
37 Correct 15 ms 2648 KB Output is correct
38 Correct 132 ms 2652 KB Output is correct
39 Correct 22 ms 2652 KB Output is correct
40 Correct 113 ms 2712 KB Output is correct
41 Correct 23 ms 2652 KB Output is correct
42 Correct 118 ms 2652 KB Output is correct
43 Correct 15 ms 2652 KB Output is correct
44 Correct 107 ms 2652 KB Output is correct
45 Correct 23 ms 2648 KB Output is correct
46 Correct 98 ms 2648 KB Output is correct
47 Correct 12 ms 2648 KB Output is correct
48 Correct 66 ms 2652 KB Output is correct
49 Correct 65 ms 2720 KB Output is correct
50 Correct 114 ms 2648 KB Output is correct
51 Correct 99 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 609 ms 4008 KB Output is correct
2 Correct 115 ms 3724 KB Output is correct
3 Correct 571 ms 3732 KB Output is correct
4 Correct 81 ms 3728 KB Output is correct
5 Correct 557 ms 3980 KB Output is correct
6 Correct 62 ms 3736 KB Output is correct
7 Correct 547 ms 3736 KB Output is correct
8 Correct 95 ms 3732 KB Output is correct
9 Correct 566 ms 3732 KB Output is correct
10 Correct 63 ms 3736 KB Output is correct
11 Correct 518 ms 3756 KB Output is correct
12 Correct 74 ms 3724 KB Output is correct
13 Correct 522 ms 3736 KB Output is correct
14 Correct 564 ms 3732 KB Output is correct
15 Correct 63 ms 3732 KB Output is correct
16 Correct 521 ms 3736 KB Output is correct
17 Correct 63 ms 3728 KB Output is correct
18 Correct 528 ms 3736 KB Output is correct
19 Correct 73 ms 3736 KB Output is correct
20 Correct 572 ms 3744 KB Output is correct
21 Correct 56 ms 3728 KB Output is correct
22 Correct 400 ms 3764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 2 ms 2392 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 2 ms 2464 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2392 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
15 Correct 3 ms 2396 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 2 ms 2396 KB Output is correct
18 Correct 2 ms 2392 KB Output is correct
19 Correct 2 ms 2392 KB Output is correct
20 Correct 2 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 2 ms 2392 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 3 ms 2404 KB Output is correct
26 Correct 103 ms 2648 KB Output is correct
27 Correct 27 ms 2648 KB Output is correct
28 Correct 104 ms 2712 KB Output is correct
29 Correct 15 ms 2732 KB Output is correct
30 Correct 109 ms 2652 KB Output is correct
31 Correct 16 ms 2652 KB Output is correct
32 Correct 122 ms 2652 KB Output is correct
33 Correct 16 ms 2652 KB Output is correct
34 Correct 9 ms 2652 KB Output is correct
35 Correct 21 ms 2648 KB Output is correct
36 Correct 115 ms 2732 KB Output is correct
37 Correct 15 ms 2648 KB Output is correct
38 Correct 132 ms 2652 KB Output is correct
39 Correct 22 ms 2652 KB Output is correct
40 Correct 113 ms 2712 KB Output is correct
41 Correct 23 ms 2652 KB Output is correct
42 Correct 118 ms 2652 KB Output is correct
43 Correct 15 ms 2652 KB Output is correct
44 Correct 107 ms 2652 KB Output is correct
45 Correct 23 ms 2648 KB Output is correct
46 Correct 98 ms 2648 KB Output is correct
47 Correct 12 ms 2648 KB Output is correct
48 Correct 66 ms 2652 KB Output is correct
49 Correct 65 ms 2720 KB Output is correct
50 Correct 114 ms 2648 KB Output is correct
51 Correct 99 ms 2648 KB Output is correct
52 Correct 609 ms 4008 KB Output is correct
53 Correct 115 ms 3724 KB Output is correct
54 Correct 571 ms 3732 KB Output is correct
55 Correct 81 ms 3728 KB Output is correct
56 Correct 557 ms 3980 KB Output is correct
57 Correct 62 ms 3736 KB Output is correct
58 Correct 547 ms 3736 KB Output is correct
59 Correct 95 ms 3732 KB Output is correct
60 Correct 566 ms 3732 KB Output is correct
61 Correct 63 ms 3736 KB Output is correct
62 Correct 518 ms 3756 KB Output is correct
63 Correct 74 ms 3724 KB Output is correct
64 Correct 522 ms 3736 KB Output is correct
65 Correct 564 ms 3732 KB Output is correct
66 Correct 63 ms 3732 KB Output is correct
67 Correct 521 ms 3736 KB Output is correct
68 Correct 63 ms 3728 KB Output is correct
69 Correct 528 ms 3736 KB Output is correct
70 Correct 73 ms 3736 KB Output is correct
71 Correct 572 ms 3744 KB Output is correct
72 Correct 56 ms 3728 KB Output is correct
73 Correct 400 ms 3764 KB Output is correct
74 Correct 1709 ms 6420 KB Output is correct
75 Correct 96 ms 6388 KB Output is correct
76 Correct 1765 ms 6336 KB Output is correct
77 Correct 107 ms 6400 KB Output is correct
78 Correct 1675 ms 6424 KB Output is correct
79 Correct 1628 ms 6456 KB Output is correct
80 Correct 108 ms 6404 KB Output is correct
81 Correct 95 ms 6420 KB Output is correct
82 Correct 1532 ms 6344 KB Output is correct
83 Correct 1669 ms 6452 KB Output is correct
84 Correct 72 ms 6420 KB Output is correct
85 Correct 1525 ms 6508 KB Output is correct
86 Correct 76 ms 6408 KB Output is correct
87 Correct 1690 ms 6512 KB Output is correct
88 Correct 90 ms 6412 KB Output is correct
89 Correct 1708 ms 6420 KB Output is correct
90 Correct 86 ms 6412 KB Output is correct
91 Correct 1538 ms 6664 KB Output is correct
92 Correct 78 ms 6408 KB Output is correct
93 Correct 1533 ms 6436 KB Output is correct
94 Correct 170 ms 6408 KB Output is correct
95 Correct 982 ms 6420 KB Output is correct
96 Correct 989 ms 6416 KB Output is correct
97 Correct 1604 ms 6664 KB Output is correct
98 Correct 1591 ms 6664 KB Output is correct