Submission #260757

# Submission time Handle Problem Language Result Execution time Memory
260757 2020-08-10T20:49:57 Z fivefourthreeone Tug of War (BOI15_tug) C++17
100 / 100
1626 ms 10624 KB
//#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>*/
 
using ll = long long;
using ld = long double;
const ll MOD = 998244353;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 30001;
//remove 0/1 spot stuff
//everything left has 2 possible people
//decompose into graph and do knapsack
multiset<ttgl> adj[2*mxN];
int deg[2*mxN];
bitset<40*mxN> dp;
int n, k;
int dfs(int u) {
    int res = 0;
    if(adj[u].size()) {
        auto nxt = *adj[u].begin();
        res+=nxt.second * (u<n ? 1 : -1);
        adj[u].erase(adj[u].find(nxt));
        adj[nxt.first].erase(adj[nxt.first].find({u, nxt.second}));
        res+=dfs(nxt.first);
    }
    return res;
}
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>k;
    int a, b, c;
    owo(i, 0, 2*n) {
        cin>>a>>b>>c;
        a--; b--;
        b+=n;
        adj[a].insert({b, c});
        adj[b].insert({a, c});
        deg[a]++; deg[b]++;
    }
    int mid = 20*n;
    queue<int> Q;
    owo(i, 0, 2*n) {
        if(deg[i]==0) {
            cout<<"NO\n";
            exit(0);
        }
        if(deg[i]==1) {
            Q.push(i);
        }
    }
    while(!Q.empty()) {
        int u = Q.front();
        Q.pop();
        if(adj[u].size()==0) {
            cout<<"NO\n";
            exit(0);
        }
        ttgl nxt = *adj[u].begin();
        mid+=nxt.second * (u<n ? 1 : -1);
        adj[nxt.first].erase(adj[nxt.first].find({u, nxt.second}));
        if(adj[nxt.first].size()==1) Q.push(nxt.first);
    }
    vector<int> kk;
    owo(i, 0, 2*n) {
        if(adj[i].size()<=1)continue;
        int nxt = dfs(i);
        if(nxt<0)nxt*=-1;
        mid-=nxt;
        kk.senpai(2*nxt);
    }
    dp[mid] = 1;
    for(int p: kk) {
        dp|=dp<<p;
    }
    bool ok = false;
    owo(i, 20*n-k, 20*n+k+1) {
        ok|=dp[i];
        if(ok)break;
    }
    cout<<(ok ? "YES\n" : "NO\n");
    return 0;
}

Compilation message

tug.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
tug.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3584 KB Output is correct
2 Correct 3 ms 3584 KB Output is correct
3 Correct 3 ms 3584 KB Output is correct
4 Correct 3 ms 3584 KB Output is correct
5 Correct 3 ms 3584 KB Output is correct
6 Correct 4 ms 3712 KB Output is correct
7 Correct 3 ms 3584 KB Output is correct
8 Correct 3 ms 3584 KB Output is correct
9 Correct 3 ms 3584 KB Output is correct
10 Correct 3 ms 3584 KB Output is correct
11 Correct 3 ms 3584 KB Output is correct
12 Correct 3 ms 3584 KB Output is correct
13 Correct 3 ms 3584 KB Output is correct
14 Correct 3 ms 3584 KB Output is correct
15 Correct 4 ms 3584 KB Output is correct
16 Correct 3 ms 3584 KB Output is correct
17 Correct 3 ms 3584 KB Output is correct
18 Correct 3 ms 3584 KB Output is correct
19 Correct 3 ms 3584 KB Output is correct
20 Correct 3 ms 3584 KB Output is correct
21 Correct 3 ms 3200 KB Output is correct
22 Correct 3 ms 3584 KB Output is correct
23 Correct 3 ms 3584 KB Output is correct
24 Correct 3 ms 3584 KB Output is correct
25 Correct 3 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3584 KB Output is correct
2 Correct 3 ms 3584 KB Output is correct
3 Correct 3 ms 3584 KB Output is correct
4 Correct 3 ms 3584 KB Output is correct
5 Correct 3 ms 3584 KB Output is correct
6 Correct 4 ms 3712 KB Output is correct
7 Correct 3 ms 3584 KB Output is correct
8 Correct 3 ms 3584 KB Output is correct
9 Correct 3 ms 3584 KB Output is correct
10 Correct 3 ms 3584 KB Output is correct
11 Correct 3 ms 3584 KB Output is correct
12 Correct 3 ms 3584 KB Output is correct
13 Correct 3 ms 3584 KB Output is correct
14 Correct 3 ms 3584 KB Output is correct
15 Correct 4 ms 3584 KB Output is correct
16 Correct 3 ms 3584 KB Output is correct
17 Correct 3 ms 3584 KB Output is correct
18 Correct 3 ms 3584 KB Output is correct
19 Correct 3 ms 3584 KB Output is correct
20 Correct 3 ms 3584 KB Output is correct
21 Correct 3 ms 3200 KB Output is correct
22 Correct 3 ms 3584 KB Output is correct
23 Correct 3 ms 3584 KB Output is correct
24 Correct 3 ms 3584 KB Output is correct
25 Correct 3 ms 3584 KB Output is correct
26 Correct 107 ms 4052 KB Output is correct
27 Correct 19 ms 3968 KB Output is correct
28 Correct 110 ms 3968 KB Output is correct
29 Correct 21 ms 3968 KB Output is correct
30 Correct 107 ms 3968 KB Output is correct
31 Correct 19 ms 3968 KB Output is correct
32 Correct 105 ms 4052 KB Output is correct
33 Correct 19 ms 3968 KB Output is correct
34 Correct 12 ms 3968 KB Output is correct
35 Correct 19 ms 3968 KB Output is correct
36 Correct 107 ms 4056 KB Output is correct
37 Correct 19 ms 4000 KB Output is correct
38 Correct 107 ms 3968 KB Output is correct
39 Correct 19 ms 3968 KB Output is correct
40 Correct 105 ms 4088 KB Output is correct
41 Correct 19 ms 3968 KB Output is correct
42 Correct 109 ms 4052 KB Output is correct
43 Correct 19 ms 3968 KB Output is correct
44 Correct 129 ms 3968 KB Output is correct
45 Correct 19 ms 4036 KB Output is correct
46 Correct 107 ms 3968 KB Output is correct
47 Correct 6 ms 3584 KB Output is correct
48 Correct 55 ms 4088 KB Output is correct
49 Correct 56 ms 3968 KB Output is correct
50 Correct 109 ms 4048 KB Output is correct
51 Correct 123 ms 3968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 400 ms 5704 KB Output is correct
2 Correct 13 ms 5120 KB Output is correct
3 Correct 380 ms 5704 KB Output is correct
4 Correct 14 ms 5120 KB Output is correct
5 Correct 371 ms 5708 KB Output is correct
6 Correct 13 ms 5120 KB Output is correct
7 Correct 374 ms 5752 KB Output is correct
8 Correct 13 ms 5120 KB Output is correct
9 Correct 363 ms 5708 KB Output is correct
10 Correct 13 ms 5120 KB Output is correct
11 Correct 388 ms 5708 KB Output is correct
12 Correct 14 ms 5120 KB Output is correct
13 Correct 365 ms 5752 KB Output is correct
14 Correct 378 ms 5632 KB Output is correct
15 Correct 13 ms 5120 KB Output is correct
16 Correct 381 ms 5776 KB Output is correct
17 Correct 14 ms 5120 KB Output is correct
18 Correct 364 ms 5752 KB Output is correct
19 Correct 13 ms 5120 KB Output is correct
20 Correct 374 ms 5708 KB Output is correct
21 Correct 14 ms 5120 KB Output is correct
22 Correct 194 ms 5756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3584 KB Output is correct
2 Correct 3 ms 3584 KB Output is correct
3 Correct 3 ms 3584 KB Output is correct
4 Correct 3 ms 3584 KB Output is correct
5 Correct 3 ms 3584 KB Output is correct
6 Correct 4 ms 3712 KB Output is correct
7 Correct 3 ms 3584 KB Output is correct
8 Correct 3 ms 3584 KB Output is correct
9 Correct 3 ms 3584 KB Output is correct
10 Correct 3 ms 3584 KB Output is correct
11 Correct 3 ms 3584 KB Output is correct
12 Correct 3 ms 3584 KB Output is correct
13 Correct 3 ms 3584 KB Output is correct
14 Correct 3 ms 3584 KB Output is correct
15 Correct 4 ms 3584 KB Output is correct
16 Correct 3 ms 3584 KB Output is correct
17 Correct 3 ms 3584 KB Output is correct
18 Correct 3 ms 3584 KB Output is correct
19 Correct 3 ms 3584 KB Output is correct
20 Correct 3 ms 3584 KB Output is correct
21 Correct 3 ms 3200 KB Output is correct
22 Correct 3 ms 3584 KB Output is correct
23 Correct 3 ms 3584 KB Output is correct
24 Correct 3 ms 3584 KB Output is correct
25 Correct 3 ms 3584 KB Output is correct
26 Correct 107 ms 4052 KB Output is correct
27 Correct 19 ms 3968 KB Output is correct
28 Correct 110 ms 3968 KB Output is correct
29 Correct 21 ms 3968 KB Output is correct
30 Correct 107 ms 3968 KB Output is correct
31 Correct 19 ms 3968 KB Output is correct
32 Correct 105 ms 4052 KB Output is correct
33 Correct 19 ms 3968 KB Output is correct
34 Correct 12 ms 3968 KB Output is correct
35 Correct 19 ms 3968 KB Output is correct
36 Correct 107 ms 4056 KB Output is correct
37 Correct 19 ms 4000 KB Output is correct
38 Correct 107 ms 3968 KB Output is correct
39 Correct 19 ms 3968 KB Output is correct
40 Correct 105 ms 4088 KB Output is correct
41 Correct 19 ms 3968 KB Output is correct
42 Correct 109 ms 4052 KB Output is correct
43 Correct 19 ms 3968 KB Output is correct
44 Correct 129 ms 3968 KB Output is correct
45 Correct 19 ms 4036 KB Output is correct
46 Correct 107 ms 3968 KB Output is correct
47 Correct 6 ms 3584 KB Output is correct
48 Correct 55 ms 4088 KB Output is correct
49 Correct 56 ms 3968 KB Output is correct
50 Correct 109 ms 4048 KB Output is correct
51 Correct 123 ms 3968 KB Output is correct
52 Correct 400 ms 5704 KB Output is correct
53 Correct 13 ms 5120 KB Output is correct
54 Correct 380 ms 5704 KB Output is correct
55 Correct 14 ms 5120 KB Output is correct
56 Correct 371 ms 5708 KB Output is correct
57 Correct 13 ms 5120 KB Output is correct
58 Correct 374 ms 5752 KB Output is correct
59 Correct 13 ms 5120 KB Output is correct
60 Correct 363 ms 5708 KB Output is correct
61 Correct 13 ms 5120 KB Output is correct
62 Correct 388 ms 5708 KB Output is correct
63 Correct 14 ms 5120 KB Output is correct
64 Correct 365 ms 5752 KB Output is correct
65 Correct 378 ms 5632 KB Output is correct
66 Correct 13 ms 5120 KB Output is correct
67 Correct 381 ms 5776 KB Output is correct
68 Correct 14 ms 5120 KB Output is correct
69 Correct 364 ms 5752 KB Output is correct
70 Correct 13 ms 5120 KB Output is correct
71 Correct 374 ms 5708 KB Output is correct
72 Correct 14 ms 5120 KB Output is correct
73 Correct 194 ms 5756 KB Output is correct
74 Correct 1624 ms 9728 KB Output is correct
75 Correct 112 ms 10232 KB Output is correct
76 Correct 1588 ms 10624 KB Output is correct
77 Correct 107 ms 10232 KB Output is correct
78 Correct 1592 ms 10500 KB Output is correct
79 Correct 1612 ms 10496 KB Output is correct
80 Correct 126 ms 10232 KB Output is correct
81 Correct 113 ms 10232 KB Output is correct
82 Correct 1626 ms 10336 KB Output is correct
83 Correct 1615 ms 10488 KB Output is correct
84 Correct 113 ms 10360 KB Output is correct
85 Correct 1617 ms 10488 KB Output is correct
86 Correct 112 ms 10360 KB Output is correct
87 Correct 1595 ms 10496 KB Output is correct
88 Correct 119 ms 10232 KB Output is correct
89 Correct 1621 ms 10488 KB Output is correct
90 Correct 116 ms 10360 KB Output is correct
91 Correct 1605 ms 10492 KB Output is correct
92 Correct 111 ms 10360 KB Output is correct
93 Correct 1605 ms 10488 KB Output is correct
94 Correct 60 ms 9848 KB Output is correct
95 Correct 823 ms 10460 KB Output is correct
96 Correct 835 ms 10480 KB Output is correct
97 Correct 1599 ms 10496 KB Output is correct
98 Correct 1584 ms 10496 KB Output is correct