Submission #1109110

# Submission time Handle Problem Language Result Execution time Memory
1109110 2024-11-06T03:59:09 Z codexistent Tug of War (BOI15_tug) C++14
71 / 100
79 ms 9976 KB
#include <bits/stdc++.h>
using namespace std;
#define MAXN 60005
#define FOR(i, a, b) for(int i = a; i <= b; i++)

multiset<pair<int, int>> e[MAXN];
bool v[MAXN];
int n, k, r = 0, r2 = 0;
bitset<MAXN> bs;

void dfs(int node){
    v[node] = true;
    if(!e[node].size()) return;
    int nxt, cost;
    tie(nxt, cost) = *e[node].begin();

    r += cost;
    if(!v[nxt]){
        e[nxt].erase(e[nxt].find({node, -cost}));
        e[node].clear();
        dfs(nxt);
    }
}

int main(){
    cin >> n >> k;
    FOR(i, 1, 2 * n){
        int l, r, s;
        cin >> l >> r >> s;

        e[l].insert({n + r, s}), e[n + r].insert({l, -s});
    }

    queue<int> q;
    FOR(i, 1, 2 * n) {
        if(e[i].size() == 1) q.push(i);
        if(e[i].size() == 0) return cout << "NO" << endl, 0;
    }

    while(q.size()){
        int qi = q.front(); q.pop();
        if(e[qi].size() == 0) return cout << "NO" << endl, 0;
        
        int nxt, cost;
        tie(nxt, cost) = *e[qi].begin();
        r += cost;

        e[qi].clear();
        e[nxt].erase(e[nxt].find({qi, -cost}));
        if(e[nxt].size() == 1) q.push(nxt);
    }

    vector<int> items;
    if(r) items.push_back(abs(r));
    FOR(i, 1, 2 * n){
        if(!v[i] && e[i].size()){
            r = 0;
            e[i].erase(e[i].begin());

            dfs(i);
            if(r) items.push_back(abs(r));
        }
    }
    r2 = accumulate(items.begin(), items.end(), 0);

    bs[0] = 1;
    for(int i : items) bs |= bs << i;
    FOR(i, 0, r2){
        if(bs[i] && abs(2 * i - r2) <= k) return cout << "YES" << endl, 0; 
    }

    return cout << "NO" << endl, 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3152 KB Output is correct
2 Correct 2 ms 3320 KB Output is correct
3 Correct 1 ms 3152 KB Output is correct
4 Correct 2 ms 3152 KB Output is correct
5 Correct 1 ms 3152 KB Output is correct
6 Correct 1 ms 3152 KB Output is correct
7 Correct 2 ms 3152 KB Output is correct
8 Correct 2 ms 3152 KB Output is correct
9 Correct 2 ms 3152 KB Output is correct
10 Correct 2 ms 3152 KB Output is correct
11 Correct 1 ms 3152 KB Output is correct
12 Correct 1 ms 3152 KB Output is correct
13 Correct 2 ms 3152 KB Output is correct
14 Correct 2 ms 3152 KB Output is correct
15 Correct 2 ms 3408 KB Output is correct
16 Correct 2 ms 3152 KB Output is correct
17 Correct 2 ms 3280 KB Output is correct
18 Correct 1 ms 3152 KB Output is correct
19 Correct 2 ms 3324 KB Output is correct
20 Correct 1 ms 3152 KB Output is correct
21 Correct 2 ms 3152 KB Output is correct
22 Correct 2 ms 3152 KB Output is correct
23 Correct 2 ms 3152 KB Output is correct
24 Correct 1 ms 3152 KB Output is correct
25 Correct 2 ms 3152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3152 KB Output is correct
2 Correct 2 ms 3320 KB Output is correct
3 Correct 1 ms 3152 KB Output is correct
4 Correct 2 ms 3152 KB Output is correct
5 Correct 1 ms 3152 KB Output is correct
6 Correct 1 ms 3152 KB Output is correct
7 Correct 2 ms 3152 KB Output is correct
8 Correct 2 ms 3152 KB Output is correct
9 Correct 2 ms 3152 KB Output is correct
10 Correct 2 ms 3152 KB Output is correct
11 Correct 1 ms 3152 KB Output is correct
12 Correct 1 ms 3152 KB Output is correct
13 Correct 2 ms 3152 KB Output is correct
14 Correct 2 ms 3152 KB Output is correct
15 Correct 2 ms 3408 KB Output is correct
16 Correct 2 ms 3152 KB Output is correct
17 Correct 2 ms 3280 KB Output is correct
18 Correct 1 ms 3152 KB Output is correct
19 Correct 2 ms 3324 KB Output is correct
20 Correct 1 ms 3152 KB Output is correct
21 Correct 2 ms 3152 KB Output is correct
22 Correct 2 ms 3152 KB Output is correct
23 Correct 2 ms 3152 KB Output is correct
24 Correct 1 ms 3152 KB Output is correct
25 Correct 2 ms 3152 KB Output is correct
26 Correct 6 ms 3664 KB Output is correct
27 Correct 5 ms 3564 KB Output is correct
28 Correct 7 ms 3664 KB Output is correct
29 Correct 4 ms 3664 KB Output is correct
30 Correct 6 ms 3664 KB Output is correct
31 Correct 5 ms 3664 KB Output is correct
32 Correct 6 ms 3664 KB Output is correct
33 Correct 5 ms 3836 KB Output is correct
34 Correct 5 ms 3696 KB Output is correct
35 Correct 5 ms 3664 KB Output is correct
36 Correct 10 ms 3532 KB Output is correct
37 Correct 5 ms 3664 KB Output is correct
38 Correct 6 ms 3732 KB Output is correct
39 Correct 5 ms 3664 KB Output is correct
40 Correct 10 ms 3728 KB Output is correct
41 Correct 5 ms 3664 KB Output is correct
42 Correct 7 ms 3664 KB Output is correct
43 Correct 5 ms 3664 KB Output is correct
44 Correct 7 ms 3664 KB Output is correct
45 Correct 4 ms 3664 KB Output is correct
46 Correct 6 ms 3548 KB Output is correct
47 Correct 4 ms 3664 KB Output is correct
48 Correct 9 ms 3664 KB Output is correct
49 Correct 5 ms 3664 KB Output is correct
50 Correct 7 ms 3664 KB Output is correct
51 Correct 9 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4944 KB Output is correct
2 Correct 13 ms 4944 KB Output is correct
3 Correct 22 ms 4944 KB Output is correct
4 Correct 14 ms 4944 KB Output is correct
5 Correct 13 ms 4944 KB Output is correct
6 Correct 19 ms 4944 KB Output is correct
7 Correct 14 ms 4944 KB Output is correct
8 Correct 16 ms 4944 KB Output is correct
9 Correct 14 ms 4944 KB Output is correct
10 Correct 14 ms 4944 KB Output is correct
11 Correct 13 ms 4944 KB Output is correct
12 Correct 14 ms 4944 KB Output is correct
13 Correct 13 ms 5096 KB Output is correct
14 Correct 13 ms 4944 KB Output is correct
15 Correct 12 ms 4944 KB Output is correct
16 Correct 13 ms 5112 KB Output is correct
17 Correct 13 ms 4944 KB Output is correct
18 Correct 13 ms 4944 KB Output is correct
19 Correct 21 ms 4944 KB Output is correct
20 Correct 13 ms 4944 KB Output is correct
21 Correct 13 ms 5112 KB Output is correct
22 Correct 14 ms 5376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3152 KB Output is correct
2 Correct 2 ms 3320 KB Output is correct
3 Correct 1 ms 3152 KB Output is correct
4 Correct 2 ms 3152 KB Output is correct
5 Correct 1 ms 3152 KB Output is correct
6 Correct 1 ms 3152 KB Output is correct
7 Correct 2 ms 3152 KB Output is correct
8 Correct 2 ms 3152 KB Output is correct
9 Correct 2 ms 3152 KB Output is correct
10 Correct 2 ms 3152 KB Output is correct
11 Correct 1 ms 3152 KB Output is correct
12 Correct 1 ms 3152 KB Output is correct
13 Correct 2 ms 3152 KB Output is correct
14 Correct 2 ms 3152 KB Output is correct
15 Correct 2 ms 3408 KB Output is correct
16 Correct 2 ms 3152 KB Output is correct
17 Correct 2 ms 3280 KB Output is correct
18 Correct 1 ms 3152 KB Output is correct
19 Correct 2 ms 3324 KB Output is correct
20 Correct 1 ms 3152 KB Output is correct
21 Correct 2 ms 3152 KB Output is correct
22 Correct 2 ms 3152 KB Output is correct
23 Correct 2 ms 3152 KB Output is correct
24 Correct 1 ms 3152 KB Output is correct
25 Correct 2 ms 3152 KB Output is correct
26 Correct 6 ms 3664 KB Output is correct
27 Correct 5 ms 3564 KB Output is correct
28 Correct 7 ms 3664 KB Output is correct
29 Correct 4 ms 3664 KB Output is correct
30 Correct 6 ms 3664 KB Output is correct
31 Correct 5 ms 3664 KB Output is correct
32 Correct 6 ms 3664 KB Output is correct
33 Correct 5 ms 3836 KB Output is correct
34 Correct 5 ms 3696 KB Output is correct
35 Correct 5 ms 3664 KB Output is correct
36 Correct 10 ms 3532 KB Output is correct
37 Correct 5 ms 3664 KB Output is correct
38 Correct 6 ms 3732 KB Output is correct
39 Correct 5 ms 3664 KB Output is correct
40 Correct 10 ms 3728 KB Output is correct
41 Correct 5 ms 3664 KB Output is correct
42 Correct 7 ms 3664 KB Output is correct
43 Correct 5 ms 3664 KB Output is correct
44 Correct 7 ms 3664 KB Output is correct
45 Correct 4 ms 3664 KB Output is correct
46 Correct 6 ms 3548 KB Output is correct
47 Correct 4 ms 3664 KB Output is correct
48 Correct 9 ms 3664 KB Output is correct
49 Correct 5 ms 3664 KB Output is correct
50 Correct 7 ms 3664 KB Output is correct
51 Correct 9 ms 3664 KB Output is correct
52 Correct 13 ms 4944 KB Output is correct
53 Correct 13 ms 4944 KB Output is correct
54 Correct 22 ms 4944 KB Output is correct
55 Correct 14 ms 4944 KB Output is correct
56 Correct 13 ms 4944 KB Output is correct
57 Correct 19 ms 4944 KB Output is correct
58 Correct 14 ms 4944 KB Output is correct
59 Correct 16 ms 4944 KB Output is correct
60 Correct 14 ms 4944 KB Output is correct
61 Correct 14 ms 4944 KB Output is correct
62 Correct 13 ms 4944 KB Output is correct
63 Correct 14 ms 4944 KB Output is correct
64 Correct 13 ms 5096 KB Output is correct
65 Correct 13 ms 4944 KB Output is correct
66 Correct 12 ms 4944 KB Output is correct
67 Correct 13 ms 5112 KB Output is correct
68 Correct 13 ms 4944 KB Output is correct
69 Correct 13 ms 4944 KB Output is correct
70 Correct 21 ms 4944 KB Output is correct
71 Correct 13 ms 4944 KB Output is correct
72 Correct 13 ms 5112 KB Output is correct
73 Correct 14 ms 5376 KB Output is correct
74 Correct 73 ms 9800 KB Output is correct
75 Correct 44 ms 9768 KB Output is correct
76 Correct 79 ms 9976 KB Output is correct
77 Correct 46 ms 9544 KB Output is correct
78 Incorrect 75 ms 9848 KB Output isn't correct
79 Halted 0 ms 0 KB -