답안 #209275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
209275 2020-03-13T14:39:02 Z stefdasca Tug of War (BOI15_tug) C++14
100 / 100
2102 ms 11256 KB
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;

int n, maxdif, skill[60002];
set<int> v[60002];

pair<int, int> vals[60002];
bool viz[60002];

int dif;

bitset<20 * 60002> dp;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> maxdif;
    for(int i = 1; i <= n+n; ++i)
    {
        int a, b;
        cin >> a >> b >> skill[i];
        b += n;
        v[a].insert(i);
        v[b].insert(i);
        vals[i] = {a, b};
    }
    deque<int> d;
    for(int i = 1; i <= n+n; ++i)
        if(v[i].size() < 2)
            d.pb(i), viz[i] = 1;
    while(!d.empty())
    {
        int poz = d[0];
        d.pop_front();
        if(v[poz].size() == 0)
        {
            cout << "NO\n";
            return 0;
        }
        int nr = *v[poz].begin();
        v[vals[nr].fi].erase(nr);
        v[vals[nr].se].erase(nr);
        if(v[vals[nr].fi].size() < 2 && !viz[vals[nr].fi])
        {
            viz[vals[nr].fi] = 1;
            d.pb(vals[nr].fi);
        }
        if(v[vals[nr].se].size() < 2 && !viz[vals[nr].se])
        {
            viz[vals[nr].se] = 1;
            d.pb(vals[nr].se);
        }
        if(poz <= n)
            dif += skill[nr];
        else
            dif -= skill[nr];
    }
    vector<int> ruk;
    for(int i = 1; i <= n+n; ++i)
    {
        if(v[i].size() < 2)
            continue;
        int valas = 0;
        int j = i;
        while(v[j].size())
        {
            int val = *v[j].begin();
            if(j <= n)
                valas += skill[val];
            else
                valas -= skill[val];
            v[vals[val].fi].erase(val);
            v[vals[val].se].erase(val);
            if(j == vals[val].fi)
                j = vals[val].se;
            else
                j = vals[val].fi;
        }
        valas = abs(valas);
        dif -= valas;
        ruk.pb(2 * valas);
    }
    dif += 20 * n;
    dp[dif] = 1;
    for(int i = 0; i < ruk.size(); ++i)
        dp = dp | (dp << ruk[i]);
    bool ok = 0;
    for(int i = 20 * n - maxdif; i <= 20 * n + maxdif; ++i)
        ok |= dp[i];
    if(ok)
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}

Compilation message

tug.cpp: In function 'int main()':
tug.cpp:88:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < ruk.size(); ++i)
                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 3704 KB Output is correct
2 Correct 7 ms 3704 KB Output is correct
3 Correct 8 ms 3832 KB Output is correct
4 Correct 7 ms 3704 KB Output is correct
5 Correct 7 ms 3832 KB Output is correct
6 Correct 7 ms 3808 KB Output is correct
7 Correct 8 ms 3704 KB Output is correct
8 Correct 8 ms 3832 KB Output is correct
9 Correct 7 ms 3704 KB Output is correct
10 Correct 8 ms 3832 KB Output is correct
11 Correct 8 ms 3832 KB Output is correct
12 Correct 7 ms 3704 KB Output is correct
13 Correct 7 ms 3704 KB Output is correct
14 Correct 7 ms 3864 KB Output is correct
15 Correct 8 ms 3708 KB Output is correct
16 Correct 8 ms 3832 KB Output is correct
17 Correct 8 ms 3704 KB Output is correct
18 Correct 8 ms 3704 KB Output is correct
19 Correct 8 ms 3704 KB Output is correct
20 Correct 7 ms 3704 KB Output is correct
21 Correct 7 ms 3192 KB Output is correct
22 Correct 7 ms 3704 KB Output is correct
23 Correct 7 ms 3704 KB Output is correct
24 Correct 7 ms 3704 KB Output is correct
25 Correct 7 ms 3704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 3704 KB Output is correct
2 Correct 7 ms 3704 KB Output is correct
3 Correct 8 ms 3832 KB Output is correct
4 Correct 7 ms 3704 KB Output is correct
5 Correct 7 ms 3832 KB Output is correct
6 Correct 7 ms 3808 KB Output is correct
7 Correct 8 ms 3704 KB Output is correct
8 Correct 8 ms 3832 KB Output is correct
9 Correct 7 ms 3704 KB Output is correct
10 Correct 8 ms 3832 KB Output is correct
11 Correct 8 ms 3832 KB Output is correct
12 Correct 7 ms 3704 KB Output is correct
13 Correct 7 ms 3704 KB Output is correct
14 Correct 7 ms 3864 KB Output is correct
15 Correct 8 ms 3708 KB Output is correct
16 Correct 8 ms 3832 KB Output is correct
17 Correct 8 ms 3704 KB Output is correct
18 Correct 8 ms 3704 KB Output is correct
19 Correct 8 ms 3704 KB Output is correct
20 Correct 7 ms 3704 KB Output is correct
21 Correct 7 ms 3192 KB Output is correct
22 Correct 7 ms 3704 KB Output is correct
23 Correct 7 ms 3704 KB Output is correct
24 Correct 7 ms 3704 KB Output is correct
25 Correct 7 ms 3704 KB Output is correct
26 Correct 134 ms 4244 KB Output is correct
27 Correct 27 ms 4216 KB Output is correct
28 Correct 139 ms 4216 KB Output is correct
29 Correct 28 ms 4216 KB Output is correct
30 Correct 135 ms 4220 KB Output is correct
31 Correct 27 ms 4220 KB Output is correct
32 Correct 136 ms 4220 KB Output is correct
33 Correct 28 ms 4216 KB Output is correct
34 Correct 18 ms 4220 KB Output is correct
35 Correct 33 ms 4216 KB Output is correct
36 Correct 137 ms 4216 KB Output is correct
37 Correct 27 ms 4216 KB Output is correct
38 Correct 140 ms 4216 KB Output is correct
39 Correct 28 ms 4216 KB Output is correct
40 Correct 142 ms 4344 KB Output is correct
41 Correct 27 ms 4216 KB Output is correct
42 Correct 140 ms 4216 KB Output is correct
43 Correct 27 ms 4216 KB Output is correct
44 Correct 155 ms 4280 KB Output is correct
45 Correct 28 ms 4300 KB Output is correct
46 Correct 142 ms 4216 KB Output is correct
47 Correct 8 ms 3576 KB Output is correct
48 Correct 75 ms 4216 KB Output is correct
49 Correct 74 ms 4216 KB Output is correct
50 Correct 145 ms 4280 KB Output is correct
51 Correct 144 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 525 ms 6264 KB Output is correct
2 Correct 18 ms 5624 KB Output is correct
3 Correct 498 ms 6136 KB Output is correct
4 Correct 19 ms 5548 KB Output is correct
5 Correct 516 ms 6136 KB Output is correct
6 Correct 17 ms 5496 KB Output is correct
7 Correct 540 ms 6264 KB Output is correct
8 Correct 17 ms 5496 KB Output is correct
9 Correct 535 ms 6264 KB Output is correct
10 Correct 17 ms 5496 KB Output is correct
11 Correct 536 ms 6244 KB Output is correct
12 Correct 18 ms 5624 KB Output is correct
13 Correct 498 ms 6248 KB Output is correct
14 Correct 506 ms 6392 KB Output is correct
15 Correct 17 ms 5496 KB Output is correct
16 Correct 550 ms 6264 KB Output is correct
17 Correct 17 ms 5500 KB Output is correct
18 Correct 522 ms 6264 KB Output is correct
19 Correct 18 ms 5496 KB Output is correct
20 Correct 514 ms 6136 KB Output is correct
21 Correct 18 ms 5624 KB Output is correct
22 Correct 263 ms 6224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 3704 KB Output is correct
2 Correct 7 ms 3704 KB Output is correct
3 Correct 8 ms 3832 KB Output is correct
4 Correct 7 ms 3704 KB Output is correct
5 Correct 7 ms 3832 KB Output is correct
6 Correct 7 ms 3808 KB Output is correct
7 Correct 8 ms 3704 KB Output is correct
8 Correct 8 ms 3832 KB Output is correct
9 Correct 7 ms 3704 KB Output is correct
10 Correct 8 ms 3832 KB Output is correct
11 Correct 8 ms 3832 KB Output is correct
12 Correct 7 ms 3704 KB Output is correct
13 Correct 7 ms 3704 KB Output is correct
14 Correct 7 ms 3864 KB Output is correct
15 Correct 8 ms 3708 KB Output is correct
16 Correct 8 ms 3832 KB Output is correct
17 Correct 8 ms 3704 KB Output is correct
18 Correct 8 ms 3704 KB Output is correct
19 Correct 8 ms 3704 KB Output is correct
20 Correct 7 ms 3704 KB Output is correct
21 Correct 7 ms 3192 KB Output is correct
22 Correct 7 ms 3704 KB Output is correct
23 Correct 7 ms 3704 KB Output is correct
24 Correct 7 ms 3704 KB Output is correct
25 Correct 7 ms 3704 KB Output is correct
26 Correct 134 ms 4244 KB Output is correct
27 Correct 27 ms 4216 KB Output is correct
28 Correct 139 ms 4216 KB Output is correct
29 Correct 28 ms 4216 KB Output is correct
30 Correct 135 ms 4220 KB Output is correct
31 Correct 27 ms 4220 KB Output is correct
32 Correct 136 ms 4220 KB Output is correct
33 Correct 28 ms 4216 KB Output is correct
34 Correct 18 ms 4220 KB Output is correct
35 Correct 33 ms 4216 KB Output is correct
36 Correct 137 ms 4216 KB Output is correct
37 Correct 27 ms 4216 KB Output is correct
38 Correct 140 ms 4216 KB Output is correct
39 Correct 28 ms 4216 KB Output is correct
40 Correct 142 ms 4344 KB Output is correct
41 Correct 27 ms 4216 KB Output is correct
42 Correct 140 ms 4216 KB Output is correct
43 Correct 27 ms 4216 KB Output is correct
44 Correct 155 ms 4280 KB Output is correct
45 Correct 28 ms 4300 KB Output is correct
46 Correct 142 ms 4216 KB Output is correct
47 Correct 8 ms 3576 KB Output is correct
48 Correct 75 ms 4216 KB Output is correct
49 Correct 74 ms 4216 KB Output is correct
50 Correct 145 ms 4280 KB Output is correct
51 Correct 144 ms 4344 KB Output is correct
52 Correct 525 ms 6264 KB Output is correct
53 Correct 18 ms 5624 KB Output is correct
54 Correct 498 ms 6136 KB Output is correct
55 Correct 19 ms 5548 KB Output is correct
56 Correct 516 ms 6136 KB Output is correct
57 Correct 17 ms 5496 KB Output is correct
58 Correct 540 ms 6264 KB Output is correct
59 Correct 17 ms 5496 KB Output is correct
60 Correct 535 ms 6264 KB Output is correct
61 Correct 17 ms 5496 KB Output is correct
62 Correct 536 ms 6244 KB Output is correct
63 Correct 18 ms 5624 KB Output is correct
64 Correct 498 ms 6248 KB Output is correct
65 Correct 506 ms 6392 KB Output is correct
66 Correct 17 ms 5496 KB Output is correct
67 Correct 550 ms 6264 KB Output is correct
68 Correct 17 ms 5500 KB Output is correct
69 Correct 522 ms 6264 KB Output is correct
70 Correct 18 ms 5496 KB Output is correct
71 Correct 514 ms 6136 KB Output is correct
72 Correct 18 ms 5624 KB Output is correct
73 Correct 263 ms 6224 KB Output is correct
74 Correct 2009 ms 11128 KB Output is correct
75 Correct 150 ms 10944 KB Output is correct
76 Correct 2000 ms 11128 KB Output is correct
77 Correct 135 ms 10872 KB Output is correct
78 Correct 2085 ms 11128 KB Output is correct
79 Correct 1998 ms 11132 KB Output is correct
80 Correct 140 ms 11000 KB Output is correct
81 Correct 139 ms 10872 KB Output is correct
82 Correct 2009 ms 10872 KB Output is correct
83 Correct 1983 ms 11128 KB Output is correct
84 Correct 148 ms 11000 KB Output is correct
85 Correct 2041 ms 11128 KB Output is correct
86 Correct 133 ms 10872 KB Output is correct
87 Correct 2013 ms 11128 KB Output is correct
88 Correct 136 ms 11000 KB Output is correct
89 Correct 1976 ms 11128 KB Output is correct
90 Correct 131 ms 10872 KB Output is correct
91 Correct 2009 ms 11128 KB Output is correct
92 Correct 143 ms 10872 KB Output is correct
93 Correct 2025 ms 11128 KB Output is correct
94 Correct 53 ms 10488 KB Output is correct
95 Correct 1066 ms 11256 KB Output is correct
96 Correct 1045 ms 11128 KB Output is correct
97 Correct 2102 ms 11132 KB Output is correct
98 Correct 2005 ms 11128 KB Output is correct