답안 #403187

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403187 2021-05-12T22:21:09 Z gevacrt Tug of War (BOI15_tug) C++17
71 / 100
254 ms 29336 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()

int N, K;
vector<unordered_set<int>> adj; vi S;

int TOT = 0, CNT = 0;
void remove_singular(int x){
    auto u = *adj[x].begin(); adj[x].clear();
    adj[u].erase(x);

    if(x < 3*N) TOT += S[u], CNT++;
    else CNT--;

    auto v = *adj[u].begin(); adj[u].clear();
    adj[v].erase(u);

    if(adj[v].size() == 1) remove_singular(v);    
}

vi vis;
void dfs(int u, int c, int h[]){
    h[c] += S[u]; vis[u] = 1;

    for(auto v : adj[u]){
        if(vis[v]) continue;
        dfs(v, (c+1)%4, h);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> N >> K;

    adj.resize(4*N); S.resize(4*N);
    for(int x = 0; x < 2*N; x++){
        int l, r; cin >> l >> r >> S[x];
        l--, r--; r += N;

        adj[x].insert(2*N+l);
        adj[2*N+l].insert(x);
    
        adj[x].insert(2*N+r);
        adj[2*N+r].insert(x);
    }

    // find single nodes
    for(int x = 2*N; x < 4*N; x++){
        if(adj[x].size() == 1)
            remove_singular(x);
    }

    for(int x = 2*N; x < 4*N; x++){
        if(adj[x].size() != 2 and adj[x].size() != 0){
            cout << "NO" << endl; return 0;
        }
    }
    assert(CNT == 0);

    bitset<60010> KP;
    KP[TOT] = 1;

    vis.resize(4*N);
    for(int x = 0; x < 2*N; x++){
        if(adj[x].empty() or vis[x]) continue;
        int h[4] = {}; dfs(x, 0, h);

        KP = (KP<<h[0]) | (KP<<h[2]);
    }
    
    int SUN = accumulate(all(S), 0);
    for(int i = 0; i < 60010; i++){
        if(KP[i]&1 and abs(SUN-2*i) <= K){
            cout << "YES\n";
            return 0;
        }
    }

    cout << "NO\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 14 ms 2188 KB Output is correct
27 Correct 7 ms 2252 KB Output is correct
28 Correct 16 ms 2292 KB Output is correct
29 Correct 7 ms 2232 KB Output is correct
30 Correct 14 ms 2252 KB Output is correct
31 Correct 8 ms 2272 KB Output is correct
32 Correct 15 ms 2280 KB Output is correct
33 Correct 7 ms 2188 KB Output is correct
34 Correct 7 ms 2124 KB Output is correct
35 Correct 8 ms 2252 KB Output is correct
36 Correct 14 ms 2272 KB Output is correct
37 Correct 6 ms 2276 KB Output is correct
38 Correct 17 ms 2288 KB Output is correct
39 Correct 7 ms 2252 KB Output is correct
40 Correct 14 ms 2252 KB Output is correct
41 Correct 8 ms 2252 KB Output is correct
42 Correct 15 ms 2280 KB Output is correct
43 Correct 7 ms 2252 KB Output is correct
44 Correct 14 ms 2296 KB Output is correct
45 Correct 7 ms 2192 KB Output is correct
46 Correct 14 ms 2292 KB Output is correct
47 Correct 6 ms 2124 KB Output is correct
48 Correct 11 ms 2180 KB Output is correct
49 Correct 11 ms 2380 KB Output is correct
50 Correct 14 ms 2296 KB Output is correct
51 Correct 14 ms 2276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 9984 KB Output is correct
2 Correct 36 ms 9796 KB Output is correct
3 Correct 74 ms 9912 KB Output is correct
4 Correct 31 ms 9724 KB Output is correct
5 Correct 74 ms 9868 KB Output is correct
6 Correct 32 ms 9676 KB Output is correct
7 Correct 75 ms 9968 KB Output is correct
8 Correct 31 ms 9704 KB Output is correct
9 Correct 74 ms 9944 KB Output is correct
10 Correct 32 ms 9720 KB Output is correct
11 Correct 77 ms 9952 KB Output is correct
12 Correct 32 ms 9732 KB Output is correct
13 Correct 75 ms 9920 KB Output is correct
14 Correct 74 ms 9932 KB Output is correct
15 Correct 30 ms 9692 KB Output is correct
16 Correct 74 ms 9984 KB Output is correct
17 Correct 31 ms 9716 KB Output is correct
18 Correct 75 ms 10052 KB Output is correct
19 Correct 29 ms 9648 KB Output is correct
20 Correct 75 ms 9932 KB Output is correct
21 Correct 30 ms 9580 KB Output is correct
22 Correct 57 ms 9976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 14 ms 2188 KB Output is correct
27 Correct 7 ms 2252 KB Output is correct
28 Correct 16 ms 2292 KB Output is correct
29 Correct 7 ms 2232 KB Output is correct
30 Correct 14 ms 2252 KB Output is correct
31 Correct 8 ms 2272 KB Output is correct
32 Correct 15 ms 2280 KB Output is correct
33 Correct 7 ms 2188 KB Output is correct
34 Correct 7 ms 2124 KB Output is correct
35 Correct 8 ms 2252 KB Output is correct
36 Correct 14 ms 2272 KB Output is correct
37 Correct 6 ms 2276 KB Output is correct
38 Correct 17 ms 2288 KB Output is correct
39 Correct 7 ms 2252 KB Output is correct
40 Correct 14 ms 2252 KB Output is correct
41 Correct 8 ms 2252 KB Output is correct
42 Correct 15 ms 2280 KB Output is correct
43 Correct 7 ms 2252 KB Output is correct
44 Correct 14 ms 2296 KB Output is correct
45 Correct 7 ms 2192 KB Output is correct
46 Correct 14 ms 2292 KB Output is correct
47 Correct 6 ms 2124 KB Output is correct
48 Correct 11 ms 2180 KB Output is correct
49 Correct 11 ms 2380 KB Output is correct
50 Correct 14 ms 2296 KB Output is correct
51 Correct 14 ms 2276 KB Output is correct
52 Correct 83 ms 9984 KB Output is correct
53 Correct 36 ms 9796 KB Output is correct
54 Correct 74 ms 9912 KB Output is correct
55 Correct 31 ms 9724 KB Output is correct
56 Correct 74 ms 9868 KB Output is correct
57 Correct 32 ms 9676 KB Output is correct
58 Correct 75 ms 9968 KB Output is correct
59 Correct 31 ms 9704 KB Output is correct
60 Correct 74 ms 9944 KB Output is correct
61 Correct 32 ms 9720 KB Output is correct
62 Correct 77 ms 9952 KB Output is correct
63 Correct 32 ms 9732 KB Output is correct
64 Correct 75 ms 9920 KB Output is correct
65 Correct 74 ms 9932 KB Output is correct
66 Correct 30 ms 9692 KB Output is correct
67 Correct 74 ms 9984 KB Output is correct
68 Correct 31 ms 9716 KB Output is correct
69 Correct 75 ms 10052 KB Output is correct
70 Correct 29 ms 9648 KB Output is correct
71 Correct 75 ms 9932 KB Output is correct
72 Correct 30 ms 9580 KB Output is correct
73 Correct 57 ms 9976 KB Output is correct
74 Correct 254 ms 29236 KB Output is correct
75 Correct 134 ms 29280 KB Output is correct
76 Correct 247 ms 29336 KB Output is correct
77 Correct 147 ms 29264 KB Output is correct
78 Incorrect 247 ms 29292 KB Output isn't correct
79 Halted 0 ms 0 KB -