# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
310598 | 2020-10-07T13:30:18 Z | Ruxandra985 | Tug of War (BOI15_tug) | C++14 | 1085 ms | 9752 KB |
#include <bits/stdc++.h> #define DIMN 30010 using namespace std; int n; int f[4 * DIMN] , gr[4 * DIMN]; vector <pair <int , int> > v[4 * DIMN]; deque <int> dq; bitset <20 * DIMN> rcs; void dfs (int nod , int &val){ int i , vecin , cst; f[nod] = 1; for (i = 0 ; i < v[nod].size() ; i++){ vecin = v[nod][i].first; cst = v[nod][i].second; if (f[vecin]) continue; if (vecin > 2 * n && vecin <= 3 * n){ /// il bagi in a val += cst; } else if (vecin > 3 * n) { /// il bagi in b val -= cst; } dfs (vecin , val); } } int main() { FILE *fin = stdin; FILE *fout = stdout; int k , i , x , y , z , a = 0 , b = 0 , nod , vecin , cst , val , sum = 0; fscanf (fin,"%d%d",&n,&k); for (i = 1 ; i <= 2 * n ; i++){ fscanf (fin,"%d%d%d",&x,&y,&z); v[i].push_back(make_pair(2 * n + x , z)); v[2 * n + x].push_back(make_pair(i , z)); v[i].push_back(make_pair(3 * n + y , z)); v[3 * n + y].push_back(make_pair(i , z)); gr[2 * n + x]++; gr[3 * n + y]++; } for (i = 2 * n + 1 ; i <= 4 * n ; i++){ if (gr[i] == 1){ dq.push_back(i); } } while (!dq.empty()){ nod = dq.front(); dq.pop_front(); f[nod] = 1; /// pozitia asta a fost luata for (i = 0 ; i < v[nod].size() ; i++){ vecin = v[nod][i].first; cst = v[nod][i].second; if (!f[vecin]){ f[vecin] = 1; if (nod <= 3 * n) a += cst; else b += cst; nod = vecin; break; } } /// nod = omul for (i = 0 ; i < v[nod].size() ; i++){ vecin = v[nod][i].first; gr[vecin]--; if (gr[vecin] == 1){ dq.push_back(vecin); } } } /// faci ce este obligatoriu rcs[0] = 1; for (i = 1 ; i <= 2 * n ; i++){ if (!f[i]){ val = 0; dfs (i , val); /// val = o valoare a unui cuplaj din punctul asta val = max(val , -val); sum += val; rcs = (rcs | (rcs << val)); ///rcs e un rucsac. rcs[i] = 1 inseamna ca exista o suma de idk cate ///cuplaje care da i (in modul toate) } } for (i = 1 ; i <= 4 * n ; i++){ if (!f[i]){ fprintf (fout,"NO"); return 0; } } /// aleg un numar de cuplaje din astea si le iau valorile negative in loc /// de cele pozitive for (i = 0 ; i <= 20 * n ; i++){ if (rcs[i] && max( (a - b + sum - 2 * i) , -(a - b + sum - 2 * i) ) <= k){ fprintf (fout,"YES"); return 0; } } fprintf (fout,"NO"); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 3328 KB | Output is correct |
2 | Correct | 3 ms | 3328 KB | Output is correct |
3 | Correct | 3 ms | 3328 KB | Output is correct |
4 | Correct | 3 ms | 3328 KB | Output is correct |
5 | Correct | 3 ms | 3328 KB | Output is correct |
6 | Correct | 3 ms | 3328 KB | Output is correct |
7 | Correct | 3 ms | 3328 KB | Output is correct |
8 | Correct | 3 ms | 3328 KB | Output is correct |
9 | Correct | 3 ms | 3328 KB | Output is correct |
10 | Correct | 3 ms | 3328 KB | Output is correct |
11 | Correct | 3 ms | 3328 KB | Output is correct |
12 | Correct | 3 ms | 3328 KB | Output is correct |
13 | Correct | 3 ms | 3328 KB | Output is correct |
14 | Correct | 3 ms | 3328 KB | Output is correct |
15 | Correct | 3 ms | 3328 KB | Output is correct |
16 | Correct | 3 ms | 3328 KB | Output is correct |
17 | Correct | 3 ms | 3456 KB | Output is correct |
18 | Correct | 3 ms | 3328 KB | Output is correct |
19 | Correct | 3 ms | 3328 KB | Output is correct |
20 | Correct | 3 ms | 3328 KB | Output is correct |
21 | Correct | 3 ms | 3328 KB | Output is correct |
22 | Correct | 3 ms | 3328 KB | Output is correct |
23 | Correct | 3 ms | 3328 KB | Output is correct |
24 | Correct | 3 ms | 3328 KB | Output is correct |
25 | Correct | 3 ms | 3456 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 3328 KB | Output is correct |
2 | Correct | 3 ms | 3328 KB | Output is correct |
3 | Correct | 3 ms | 3328 KB | Output is correct |
4 | Correct | 3 ms | 3328 KB | Output is correct |
5 | Correct | 3 ms | 3328 KB | Output is correct |
6 | Correct | 3 ms | 3328 KB | Output is correct |
7 | Correct | 3 ms | 3328 KB | Output is correct |
8 | Correct | 3 ms | 3328 KB | Output is correct |
9 | Correct | 3 ms | 3328 KB | Output is correct |
10 | Correct | 3 ms | 3328 KB | Output is correct |
11 | Correct | 3 ms | 3328 KB | Output is correct |
12 | Correct | 3 ms | 3328 KB | Output is correct |
13 | Correct | 3 ms | 3328 KB | Output is correct |
14 | Correct | 3 ms | 3328 KB | Output is correct |
15 | Correct | 3 ms | 3328 KB | Output is correct |
16 | Correct | 3 ms | 3328 KB | Output is correct |
17 | Correct | 3 ms | 3456 KB | Output is correct |
18 | Correct | 3 ms | 3328 KB | Output is correct |
19 | Correct | 3 ms | 3328 KB | Output is correct |
20 | Correct | 3 ms | 3328 KB | Output is correct |
21 | Correct | 3 ms | 3328 KB | Output is correct |
22 | Correct | 3 ms | 3328 KB | Output is correct |
23 | Correct | 3 ms | 3328 KB | Output is correct |
24 | Correct | 3 ms | 3328 KB | Output is correct |
25 | Correct | 3 ms | 3456 KB | Output is correct |
26 | Correct | 71 ms | 3712 KB | Output is correct |
27 | Correct | 14 ms | 3712 KB | Output is correct |
28 | Correct | 72 ms | 3712 KB | Output is correct |
29 | Correct | 14 ms | 3712 KB | Output is correct |
30 | Correct | 72 ms | 3712 KB | Output is correct |
31 | Correct | 14 ms | 3712 KB | Output is correct |
32 | Correct | 72 ms | 3712 KB | Output is correct |
33 | Correct | 14 ms | 3712 KB | Output is correct |
34 | Correct | 10 ms | 3712 KB | Output is correct |
35 | Correct | 15 ms | 3712 KB | Output is correct |
36 | Correct | 72 ms | 3712 KB | Output is correct |
37 | Correct | 15 ms | 3712 KB | Output is correct |
38 | Correct | 72 ms | 3760 KB | Output is correct |
39 | Correct | 17 ms | 3712 KB | Output is correct |
40 | Correct | 72 ms | 3712 KB | Output is correct |
41 | Correct | 14 ms | 3712 KB | Output is correct |
42 | Correct | 75 ms | 3760 KB | Output is correct |
43 | Correct | 14 ms | 3712 KB | Output is correct |
44 | Correct | 73 ms | 3768 KB | Output is correct |
45 | Correct | 14 ms | 3712 KB | Output is correct |
46 | Correct | 74 ms | 3712 KB | Output is correct |
47 | Correct | 10 ms | 3840 KB | Output is correct |
48 | Correct | 39 ms | 3712 KB | Output is correct |
49 | Correct | 38 ms | 3712 KB | Output is correct |
50 | Correct | 77 ms | 3712 KB | Output is correct |
51 | Correct | 73 ms | 3712 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 270 ms | 5120 KB | Output is correct |
2 | Correct | 45 ms | 5248 KB | Output is correct |
3 | Correct | 266 ms | 5132 KB | Output is correct |
4 | Correct | 43 ms | 5240 KB | Output is correct |
5 | Correct | 269 ms | 5240 KB | Output is correct |
6 | Correct | 46 ms | 5248 KB | Output is correct |
7 | Correct | 267 ms | 5136 KB | Output is correct |
8 | Correct | 48 ms | 5248 KB | Output is correct |
9 | Correct | 274 ms | 5240 KB | Output is correct |
10 | Correct | 43 ms | 5248 KB | Output is correct |
11 | Correct | 274 ms | 5128 KB | Output is correct |
12 | Correct | 44 ms | 5248 KB | Output is correct |
13 | Correct | 267 ms | 5248 KB | Output is correct |
14 | Correct | 269 ms | 5240 KB | Output is correct |
15 | Correct | 45 ms | 5248 KB | Output is correct |
16 | Correct | 273 ms | 5120 KB | Output is correct |
17 | Correct | 44 ms | 5240 KB | Output is correct |
18 | Correct | 266 ms | 5240 KB | Output is correct |
19 | Correct | 42 ms | 5248 KB | Output is correct |
20 | Correct | 269 ms | 5136 KB | Output is correct |
21 | Correct | 34 ms | 5376 KB | Output is correct |
22 | Correct | 148 ms | 5388 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 3328 KB | Output is correct |
2 | Correct | 3 ms | 3328 KB | Output is correct |
3 | Correct | 3 ms | 3328 KB | Output is correct |
4 | Correct | 3 ms | 3328 KB | Output is correct |
5 | Correct | 3 ms | 3328 KB | Output is correct |
6 | Correct | 3 ms | 3328 KB | Output is correct |
7 | Correct | 3 ms | 3328 KB | Output is correct |
8 | Correct | 3 ms | 3328 KB | Output is correct |
9 | Correct | 3 ms | 3328 KB | Output is correct |
10 | Correct | 3 ms | 3328 KB | Output is correct |
11 | Correct | 3 ms | 3328 KB | Output is correct |
12 | Correct | 3 ms | 3328 KB | Output is correct |
13 | Correct | 3 ms | 3328 KB | Output is correct |
14 | Correct | 3 ms | 3328 KB | Output is correct |
15 | Correct | 3 ms | 3328 KB | Output is correct |
16 | Correct | 3 ms | 3328 KB | Output is correct |
17 | Correct | 3 ms | 3456 KB | Output is correct |
18 | Correct | 3 ms | 3328 KB | Output is correct |
19 | Correct | 3 ms | 3328 KB | Output is correct |
20 | Correct | 3 ms | 3328 KB | Output is correct |
21 | Correct | 3 ms | 3328 KB | Output is correct |
22 | Correct | 3 ms | 3328 KB | Output is correct |
23 | Correct | 3 ms | 3328 KB | Output is correct |
24 | Correct | 3 ms | 3328 KB | Output is correct |
25 | Correct | 3 ms | 3456 KB | Output is correct |
26 | Correct | 71 ms | 3712 KB | Output is correct |
27 | Correct | 14 ms | 3712 KB | Output is correct |
28 | Correct | 72 ms | 3712 KB | Output is correct |
29 | Correct | 14 ms | 3712 KB | Output is correct |
30 | Correct | 72 ms | 3712 KB | Output is correct |
31 | Correct | 14 ms | 3712 KB | Output is correct |
32 | Correct | 72 ms | 3712 KB | Output is correct |
33 | Correct | 14 ms | 3712 KB | Output is correct |
34 | Correct | 10 ms | 3712 KB | Output is correct |
35 | Correct | 15 ms | 3712 KB | Output is correct |
36 | Correct | 72 ms | 3712 KB | Output is correct |
37 | Correct | 15 ms | 3712 KB | Output is correct |
38 | Correct | 72 ms | 3760 KB | Output is correct |
39 | Correct | 17 ms | 3712 KB | Output is correct |
40 | Correct | 72 ms | 3712 KB | Output is correct |
41 | Correct | 14 ms | 3712 KB | Output is correct |
42 | Correct | 75 ms | 3760 KB | Output is correct |
43 | Correct | 14 ms | 3712 KB | Output is correct |
44 | Correct | 73 ms | 3768 KB | Output is correct |
45 | Correct | 14 ms | 3712 KB | Output is correct |
46 | Correct | 74 ms | 3712 KB | Output is correct |
47 | Correct | 10 ms | 3840 KB | Output is correct |
48 | Correct | 39 ms | 3712 KB | Output is correct |
49 | Correct | 38 ms | 3712 KB | Output is correct |
50 | Correct | 77 ms | 3712 KB | Output is correct |
51 | Correct | 73 ms | 3712 KB | Output is correct |
52 | Correct | 270 ms | 5120 KB | Output is correct |
53 | Correct | 45 ms | 5248 KB | Output is correct |
54 | Correct | 266 ms | 5132 KB | Output is correct |
55 | Correct | 43 ms | 5240 KB | Output is correct |
56 | Correct | 269 ms | 5240 KB | Output is correct |
57 | Correct | 46 ms | 5248 KB | Output is correct |
58 | Correct | 267 ms | 5136 KB | Output is correct |
59 | Correct | 48 ms | 5248 KB | Output is correct |
60 | Correct | 274 ms | 5240 KB | Output is correct |
61 | Correct | 43 ms | 5248 KB | Output is correct |
62 | Correct | 274 ms | 5128 KB | Output is correct |
63 | Correct | 44 ms | 5248 KB | Output is correct |
64 | Correct | 267 ms | 5248 KB | Output is correct |
65 | Correct | 269 ms | 5240 KB | Output is correct |
66 | Correct | 45 ms | 5248 KB | Output is correct |
67 | Correct | 273 ms | 5120 KB | Output is correct |
68 | Correct | 44 ms | 5240 KB | Output is correct |
69 | Correct | 266 ms | 5240 KB | Output is correct |
70 | Correct | 42 ms | 5248 KB | Output is correct |
71 | Correct | 269 ms | 5136 KB | Output is correct |
72 | Correct | 34 ms | 5376 KB | Output is correct |
73 | Correct | 148 ms | 5388 KB | Output is correct |
74 | Correct | 1062 ms | 8692 KB | Output is correct |
75 | Correct | 106 ms | 8696 KB | Output is correct |
76 | Correct | 1051 ms | 8696 KB | Output is correct |
77 | Correct | 113 ms | 8824 KB | Output is correct |
78 | Correct | 1085 ms | 8700 KB | Output is correct |
79 | Correct | 1079 ms | 8696 KB | Output is correct |
80 | Correct | 105 ms | 8696 KB | Output is correct |
81 | Correct | 109 ms | 8696 KB | Output is correct |
82 | Correct | 1054 ms | 8696 KB | Output is correct |
83 | Correct | 1069 ms | 8692 KB | Output is correct |
84 | Correct | 112 ms | 8692 KB | Output is correct |
85 | Correct | 1056 ms | 8692 KB | Output is correct |
86 | Correct | 104 ms | 8696 KB | Output is correct |
87 | Correct | 1070 ms | 8748 KB | Output is correct |
88 | Correct | 112 ms | 8572 KB | Output is correct |
89 | Correct | 1054 ms | 8724 KB | Output is correct |
90 | Correct | 128 ms | 8696 KB | Output is correct |
91 | Correct | 1064 ms | 8692 KB | Output is correct |
92 | Correct | 104 ms | 8696 KB | Output is correct |
93 | Correct | 1066 ms | 8696 KB | Output is correct |
94 | Correct | 133 ms | 9752 KB | Output is correct |
95 | Correct | 570 ms | 9080 KB | Output is correct |
96 | Correct | 566 ms | 9064 KB | Output is correct |
97 | Correct | 1083 ms | 8696 KB | Output is correct |
98 | Correct | 1065 ms | 8696 KB | Output is correct |