답안 #156016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
156016 2019-10-02T15:06:59 Z lyc Tug of War (BOI15_tug) C++14
100 / 100
2501 ms 11128 KB
#include <bits/stdc++.h>
using namespace std;

const int MX_N = 30001;
const int MX_S = 21;

int N, K;
int L[2*MX_N], R[2*MX_N], S[2*MX_N];
set<int> al[2*MX_N];
queue<int> q;
bitset<2*MX_N*MX_S> dp;

void die() {
    cout << "NO" << '\n';
    exit(0);
}

int main() {
    cin >> N >> K;
    for (int i = 0; i < 2*N; ++i) {
        cin >> L[i] >> R[i] >> S[i]; R[i] += N;
        al[L[i]].insert(i);
        al[R[i]].insert(i);
    }

    for (int u = 1; u <= 2*N; ++u) {
        if (al[u].empty()) die();
        else if ((int)al[u].size() == 1) q.push(u);
    }

    int mini = 0 + N*20;
    while (!q.empty()) {
        int u = q.front(); q.pop();
        if (al[u].empty()) die();
        int i = *al[u].begin();
        mini += (u <= N ? S[i] : -S[i]);
        int v = L[i] ^ R[i] ^ u;
        al[u].erase(i);
        al[v].erase(i);
        if ((int)al[v].size() == 1) q.push(v);
    }

    vector<int> flip;
    for (int l = 1; l <= N; ++l) {
        if (al[l].empty()) continue;
        int cyc = 0;
        for (int u = l; !al[u].empty();) {
            int i = *al[u].begin();
            cyc += (u <= N ? S[i] : -S[i]);
            int v = L[i] ^ R[i] ^ u;
            al[u].erase(i);
            al[v].erase(i);
            u = v;
        }
        cyc = abs(cyc);
        mini -= cyc;
        flip.push_back(2*cyc);
    }

    dp[mini] = 1;
    for (int x : flip) dp |= dp << x;
    for (int i = N*20-K; i <= N*20+K; ++i) if (dp[i]) {
        cout << "YES" << '\n';
        return 0;
    }
    die();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3548 KB Output is correct
2 Correct 6 ms 3576 KB Output is correct
3 Correct 7 ms 3548 KB Output is correct
4 Correct 6 ms 3588 KB Output is correct
5 Correct 6 ms 3576 KB Output is correct
6 Correct 6 ms 3576 KB Output is correct
7 Correct 6 ms 3580 KB Output is correct
8 Correct 6 ms 3576 KB Output is correct
9 Correct 5 ms 3576 KB Output is correct
10 Correct 6 ms 3576 KB Output is correct
11 Correct 6 ms 3548 KB Output is correct
12 Correct 5 ms 3576 KB Output is correct
13 Correct 6 ms 3576 KB Output is correct
14 Correct 6 ms 3576 KB Output is correct
15 Correct 5 ms 3576 KB Output is correct
16 Correct 6 ms 3576 KB Output is correct
17 Correct 6 ms 3640 KB Output is correct
18 Correct 6 ms 3576 KB Output is correct
19 Correct 6 ms 3576 KB Output is correct
20 Correct 6 ms 3576 KB Output is correct
21 Correct 4 ms 3192 KB Output is correct
22 Correct 5 ms 3576 KB Output is correct
23 Correct 5 ms 3648 KB Output is correct
24 Correct 5 ms 3576 KB Output is correct
25 Correct 6 ms 3544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3548 KB Output is correct
2 Correct 6 ms 3576 KB Output is correct
3 Correct 7 ms 3548 KB Output is correct
4 Correct 6 ms 3588 KB Output is correct
5 Correct 6 ms 3576 KB Output is correct
6 Correct 6 ms 3576 KB Output is correct
7 Correct 6 ms 3580 KB Output is correct
8 Correct 6 ms 3576 KB Output is correct
9 Correct 5 ms 3576 KB Output is correct
10 Correct 6 ms 3576 KB Output is correct
11 Correct 6 ms 3548 KB Output is correct
12 Correct 5 ms 3576 KB Output is correct
13 Correct 6 ms 3576 KB Output is correct
14 Correct 6 ms 3576 KB Output is correct
15 Correct 5 ms 3576 KB Output is correct
16 Correct 6 ms 3576 KB Output is correct
17 Correct 6 ms 3640 KB Output is correct
18 Correct 6 ms 3576 KB Output is correct
19 Correct 6 ms 3576 KB Output is correct
20 Correct 6 ms 3576 KB Output is correct
21 Correct 4 ms 3192 KB Output is correct
22 Correct 5 ms 3576 KB Output is correct
23 Correct 5 ms 3648 KB Output is correct
24 Correct 5 ms 3576 KB Output is correct
25 Correct 6 ms 3544 KB Output is correct
26 Correct 158 ms 4288 KB Output is correct
27 Correct 31 ms 4088 KB Output is correct
28 Correct 161 ms 4220 KB Output is correct
29 Correct 32 ms 4088 KB Output is correct
30 Correct 160 ms 4132 KB Output is correct
31 Correct 31 ms 4088 KB Output is correct
32 Correct 156 ms 4132 KB Output is correct
33 Correct 31 ms 4088 KB Output is correct
34 Correct 22 ms 4088 KB Output is correct
35 Correct 31 ms 4216 KB Output is correct
36 Correct 159 ms 4216 KB Output is correct
37 Correct 31 ms 4088 KB Output is correct
38 Correct 157 ms 4088 KB Output is correct
39 Correct 31 ms 4088 KB Output is correct
40 Correct 157 ms 4092 KB Output is correct
41 Correct 31 ms 4092 KB Output is correct
42 Correct 160 ms 4088 KB Output is correct
43 Correct 31 ms 4092 KB Output is correct
44 Correct 157 ms 4088 KB Output is correct
45 Correct 31 ms 4088 KB Output is correct
46 Correct 157 ms 4088 KB Output is correct
47 Correct 10 ms 3576 KB Output is correct
48 Correct 85 ms 4088 KB Output is correct
49 Correct 85 ms 4088 KB Output is correct
50 Correct 160 ms 4092 KB Output is correct
51 Correct 163 ms 4088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 494 ms 5880 KB Output is correct
2 Correct 37 ms 5752 KB Output is correct
3 Correct 479 ms 6136 KB Output is correct
4 Correct 36 ms 5500 KB Output is correct
5 Correct 505 ms 6008 KB Output is correct
6 Correct 35 ms 5500 KB Output is correct
7 Correct 537 ms 6100 KB Output is correct
8 Correct 35 ms 5500 KB Output is correct
9 Correct 487 ms 6136 KB Output is correct
10 Correct 35 ms 5492 KB Output is correct
11 Correct 481 ms 6128 KB Output is correct
12 Correct 35 ms 5496 KB Output is correct
13 Correct 488 ms 6136 KB Output is correct
14 Correct 498 ms 6092 KB Output is correct
15 Correct 34 ms 5496 KB Output is correct
16 Correct 487 ms 6132 KB Output is correct
17 Correct 34 ms 5500 KB Output is correct
18 Correct 478 ms 6136 KB Output is correct
19 Correct 37 ms 5496 KB Output is correct
20 Correct 478 ms 6008 KB Output is correct
21 Correct 36 ms 5500 KB Output is correct
22 Correct 268 ms 6008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3548 KB Output is correct
2 Correct 6 ms 3576 KB Output is correct
3 Correct 7 ms 3548 KB Output is correct
4 Correct 6 ms 3588 KB Output is correct
5 Correct 6 ms 3576 KB Output is correct
6 Correct 6 ms 3576 KB Output is correct
7 Correct 6 ms 3580 KB Output is correct
8 Correct 6 ms 3576 KB Output is correct
9 Correct 5 ms 3576 KB Output is correct
10 Correct 6 ms 3576 KB Output is correct
11 Correct 6 ms 3548 KB Output is correct
12 Correct 5 ms 3576 KB Output is correct
13 Correct 6 ms 3576 KB Output is correct
14 Correct 6 ms 3576 KB Output is correct
15 Correct 5 ms 3576 KB Output is correct
16 Correct 6 ms 3576 KB Output is correct
17 Correct 6 ms 3640 KB Output is correct
18 Correct 6 ms 3576 KB Output is correct
19 Correct 6 ms 3576 KB Output is correct
20 Correct 6 ms 3576 KB Output is correct
21 Correct 4 ms 3192 KB Output is correct
22 Correct 5 ms 3576 KB Output is correct
23 Correct 5 ms 3648 KB Output is correct
24 Correct 5 ms 3576 KB Output is correct
25 Correct 6 ms 3544 KB Output is correct
26 Correct 158 ms 4288 KB Output is correct
27 Correct 31 ms 4088 KB Output is correct
28 Correct 161 ms 4220 KB Output is correct
29 Correct 32 ms 4088 KB Output is correct
30 Correct 160 ms 4132 KB Output is correct
31 Correct 31 ms 4088 KB Output is correct
32 Correct 156 ms 4132 KB Output is correct
33 Correct 31 ms 4088 KB Output is correct
34 Correct 22 ms 4088 KB Output is correct
35 Correct 31 ms 4216 KB Output is correct
36 Correct 159 ms 4216 KB Output is correct
37 Correct 31 ms 4088 KB Output is correct
38 Correct 157 ms 4088 KB Output is correct
39 Correct 31 ms 4088 KB Output is correct
40 Correct 157 ms 4092 KB Output is correct
41 Correct 31 ms 4092 KB Output is correct
42 Correct 160 ms 4088 KB Output is correct
43 Correct 31 ms 4092 KB Output is correct
44 Correct 157 ms 4088 KB Output is correct
45 Correct 31 ms 4088 KB Output is correct
46 Correct 157 ms 4088 KB Output is correct
47 Correct 10 ms 3576 KB Output is correct
48 Correct 85 ms 4088 KB Output is correct
49 Correct 85 ms 4088 KB Output is correct
50 Correct 160 ms 4092 KB Output is correct
51 Correct 163 ms 4088 KB Output is correct
52 Correct 494 ms 5880 KB Output is correct
53 Correct 37 ms 5752 KB Output is correct
54 Correct 479 ms 6136 KB Output is correct
55 Correct 36 ms 5500 KB Output is correct
56 Correct 505 ms 6008 KB Output is correct
57 Correct 35 ms 5500 KB Output is correct
58 Correct 537 ms 6100 KB Output is correct
59 Correct 35 ms 5500 KB Output is correct
60 Correct 487 ms 6136 KB Output is correct
61 Correct 35 ms 5492 KB Output is correct
62 Correct 481 ms 6128 KB Output is correct
63 Correct 35 ms 5496 KB Output is correct
64 Correct 488 ms 6136 KB Output is correct
65 Correct 498 ms 6092 KB Output is correct
66 Correct 34 ms 5496 KB Output is correct
67 Correct 487 ms 6132 KB Output is correct
68 Correct 34 ms 5500 KB Output is correct
69 Correct 478 ms 6136 KB Output is correct
70 Correct 37 ms 5496 KB Output is correct
71 Correct 478 ms 6008 KB Output is correct
72 Correct 36 ms 5500 KB Output is correct
73 Correct 268 ms 6008 KB Output is correct
74 Correct 2371 ms 11040 KB Output is correct
75 Correct 201 ms 10788 KB Output is correct
76 Correct 2327 ms 11040 KB Output is correct
77 Correct 199 ms 10744 KB Output is correct
78 Correct 2353 ms 10976 KB Output is correct
79 Correct 2501 ms 11000 KB Output is correct
80 Correct 205 ms 10756 KB Output is correct
81 Correct 201 ms 10776 KB Output is correct
82 Correct 2334 ms 10784 KB Output is correct
83 Correct 2319 ms 11128 KB Output is correct
84 Correct 208 ms 10744 KB Output is correct
85 Correct 2341 ms 11040 KB Output is correct
86 Correct 206 ms 10872 KB Output is correct
87 Correct 2344 ms 11128 KB Output is correct
88 Correct 204 ms 10872 KB Output is correct
89 Correct 2324 ms 11036 KB Output is correct
90 Correct 209 ms 10744 KB Output is correct
91 Correct 2300 ms 11128 KB Output is correct
92 Correct 206 ms 10788 KB Output is correct
93 Correct 2333 ms 11128 KB Output is correct
94 Correct 124 ms 10232 KB Output is correct
95 Correct 1236 ms 10924 KB Output is correct
96 Correct 1229 ms 11000 KB Output is correct
97 Correct 2374 ms 11000 KB Output is correct
98 Correct 2397 ms 11128 KB Output is correct