# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
314271 | 2020-10-19T10:13:40 Z | mat_v | Power Plant (JOI20_power) | C++14 | 201 ms | 27704 KB |
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i)) #define mod 998244353 #define xx first #define yy second #define all(a) (a).begin(), (a).end() #define pb push_back #define ll long long #define pii pair<int,int> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less) mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int n; int niz[200005]; vector<int> graf[200005]; int dp[200005]; bool bio[200005]; int cale[200005]; int solve(int x, int y){ //if(bio[x])return dp[x]; //bio[x] = 1; cale[x] = y; int tmp = 0; for(auto c:graf[x]){ if(c == y)continue; tmp += solve(c, x); } dp[x] = tmp - niz[x]; dp[x] = max(dp[x], niz[x]); return dp[x]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; ff(i,1,n - 1){ int a,b; cin >> a >> b; graf[a].pb(b); graf[b].pb(a); } string s; cin >> s; ff(i,0,n - 1)niz[i + 1] = (s[i] - '0'); int ans = solve(1, -1); ff(i,1,n){ ans = max(ans, dp[i]); for(auto c:graf[i]){ if(c == cale[i])continue; ans = max(ans, dp[c] + niz[i]); } } cout << ans << "\n"; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4992 KB | Output is correct |
2 | Correct | 4 ms | 4992 KB | Output is correct |
3 | Correct | 4 ms | 4992 KB | Output is correct |
4 | Correct | 4 ms | 4992 KB | Output is correct |
5 | Correct | 4 ms | 4992 KB | Output is correct |
6 | Correct | 4 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 4992 KB | Output is correct |
8 | Correct | 4 ms | 4992 KB | Output is correct |
9 | Correct | 4 ms | 5120 KB | Output is correct |
10 | Correct | 4 ms | 4992 KB | Output is correct |
11 | Correct | 4 ms | 4992 KB | Output is correct |
12 | Correct | 4 ms | 4992 KB | Output is correct |
13 | Correct | 3 ms | 4992 KB | Output is correct |
14 | Correct | 4 ms | 4992 KB | Output is correct |
15 | Correct | 4 ms | 4992 KB | Output is correct |
16 | Correct | 4 ms | 4992 KB | Output is correct |
17 | Correct | 4 ms | 4992 KB | Output is correct |
18 | Correct | 4 ms | 4992 KB | Output is correct |
19 | Correct | 4 ms | 4992 KB | Output is correct |
20 | Correct | 4 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 4992 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4992 KB | Output is correct |
2 | Correct | 4 ms | 4992 KB | Output is correct |
3 | Correct | 4 ms | 4992 KB | Output is correct |
4 | Correct | 4 ms | 4992 KB | Output is correct |
5 | Correct | 4 ms | 4992 KB | Output is correct |
6 | Correct | 4 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 4992 KB | Output is correct |
8 | Correct | 4 ms | 4992 KB | Output is correct |
9 | Correct | 4 ms | 5120 KB | Output is correct |
10 | Correct | 4 ms | 4992 KB | Output is correct |
11 | Correct | 4 ms | 4992 KB | Output is correct |
12 | Correct | 4 ms | 4992 KB | Output is correct |
13 | Correct | 3 ms | 4992 KB | Output is correct |
14 | Correct | 4 ms | 4992 KB | Output is correct |
15 | Correct | 4 ms | 4992 KB | Output is correct |
16 | Correct | 4 ms | 4992 KB | Output is correct |
17 | Correct | 4 ms | 4992 KB | Output is correct |
18 | Correct | 4 ms | 4992 KB | Output is correct |
19 | Correct | 4 ms | 4992 KB | Output is correct |
20 | Correct | 4 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 4992 KB | Output is correct |
22 | Correct | 5 ms | 5120 KB | Output is correct |
23 | Correct | 4 ms | 5120 KB | Output is correct |
24 | Correct | 4 ms | 5120 KB | Output is correct |
25 | Correct | 5 ms | 5120 KB | Output is correct |
26 | Correct | 4 ms | 5120 KB | Output is correct |
27 | Correct | 4 ms | 5120 KB | Output is correct |
28 | Correct | 4 ms | 5120 KB | Output is correct |
29 | Correct | 4 ms | 5248 KB | Output is correct |
30 | Correct | 4 ms | 5248 KB | Output is correct |
31 | Correct | 4 ms | 5120 KB | Output is correct |
32 | Correct | 5 ms | 5120 KB | Output is correct |
33 | Correct | 4 ms | 5120 KB | Output is correct |
34 | Correct | 4 ms | 5120 KB | Output is correct |
35 | Correct | 5 ms | 5120 KB | Output is correct |
36 | Correct | 5 ms | 5120 KB | Output is correct |
37 | Correct | 5 ms | 5248 KB | Output is correct |
38 | Correct | 5 ms | 5120 KB | Output is correct |
39 | Correct | 5 ms | 5248 KB | Output is correct |
40 | Correct | 5 ms | 5120 KB | Output is correct |
41 | Correct | 5 ms | 5248 KB | Output is correct |
42 | Correct | 4 ms | 5120 KB | Output is correct |
43 | Correct | 5 ms | 5120 KB | Output is correct |
44 | Correct | 4 ms | 5248 KB | Output is correct |
45 | Correct | 5 ms | 5120 KB | Output is correct |
46 | Correct | 4 ms | 5120 KB | Output is correct |
47 | Correct | 5 ms | 5120 KB | Output is correct |
48 | Correct | 5 ms | 5248 KB | Output is correct |
49 | Correct | 5 ms | 5248 KB | Output is correct |
50 | Correct | 5 ms | 5248 KB | Output is correct |
51 | Correct | 4 ms | 5248 KB | Output is correct |
52 | Correct | 5 ms | 5120 KB | Output is correct |
53 | Correct | 5 ms | 5120 KB | Output is correct |
54 | Correct | 4 ms | 5120 KB | Output is correct |
55 | Correct | 4 ms | 5120 KB | Output is correct |
56 | Correct | 4 ms | 5120 KB | Output is correct |
57 | Correct | 5 ms | 5248 KB | Output is correct |
58 | Correct | 5 ms | 5120 KB | Output is correct |
59 | Correct | 4 ms | 5120 KB | Output is correct |
60 | Correct | 4 ms | 5248 KB | Output is correct |
61 | Correct | 4 ms | 5120 KB | Output is correct |
62 | Correct | 4 ms | 5248 KB | Output is correct |
63 | Correct | 5 ms | 5120 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4992 KB | Output is correct |
2 | Correct | 4 ms | 4992 KB | Output is correct |
3 | Correct | 4 ms | 4992 KB | Output is correct |
4 | Correct | 4 ms | 4992 KB | Output is correct |
5 | Correct | 4 ms | 4992 KB | Output is correct |
6 | Correct | 4 ms | 4992 KB | Output is correct |
7 | Correct | 4 ms | 4992 KB | Output is correct |
8 | Correct | 4 ms | 4992 KB | Output is correct |
9 | Correct | 4 ms | 5120 KB | Output is correct |
10 | Correct | 4 ms | 4992 KB | Output is correct |
11 | Correct | 4 ms | 4992 KB | Output is correct |
12 | Correct | 4 ms | 4992 KB | Output is correct |
13 | Correct | 3 ms | 4992 KB | Output is correct |
14 | Correct | 4 ms | 4992 KB | Output is correct |
15 | Correct | 4 ms | 4992 KB | Output is correct |
16 | Correct | 4 ms | 4992 KB | Output is correct |
17 | Correct | 4 ms | 4992 KB | Output is correct |
18 | Correct | 4 ms | 4992 KB | Output is correct |
19 | Correct | 4 ms | 4992 KB | Output is correct |
20 | Correct | 4 ms | 4992 KB | Output is correct |
21 | Correct | 4 ms | 4992 KB | Output is correct |
22 | Correct | 5 ms | 5120 KB | Output is correct |
23 | Correct | 4 ms | 5120 KB | Output is correct |
24 | Correct | 4 ms | 5120 KB | Output is correct |
25 | Correct | 5 ms | 5120 KB | Output is correct |
26 | Correct | 4 ms | 5120 KB | Output is correct |
27 | Correct | 4 ms | 5120 KB | Output is correct |
28 | Correct | 4 ms | 5120 KB | Output is correct |
29 | Correct | 4 ms | 5248 KB | Output is correct |
30 | Correct | 4 ms | 5248 KB | Output is correct |
31 | Correct | 4 ms | 5120 KB | Output is correct |
32 | Correct | 5 ms | 5120 KB | Output is correct |
33 | Correct | 4 ms | 5120 KB | Output is correct |
34 | Correct | 4 ms | 5120 KB | Output is correct |
35 | Correct | 5 ms | 5120 KB | Output is correct |
36 | Correct | 5 ms | 5120 KB | Output is correct |
37 | Correct | 5 ms | 5248 KB | Output is correct |
38 | Correct | 5 ms | 5120 KB | Output is correct |
39 | Correct | 5 ms | 5248 KB | Output is correct |
40 | Correct | 5 ms | 5120 KB | Output is correct |
41 | Correct | 5 ms | 5248 KB | Output is correct |
42 | Correct | 4 ms | 5120 KB | Output is correct |
43 | Correct | 5 ms | 5120 KB | Output is correct |
44 | Correct | 4 ms | 5248 KB | Output is correct |
45 | Correct | 5 ms | 5120 KB | Output is correct |
46 | Correct | 4 ms | 5120 KB | Output is correct |
47 | Correct | 5 ms | 5120 KB | Output is correct |
48 | Correct | 5 ms | 5248 KB | Output is correct |
49 | Correct | 5 ms | 5248 KB | Output is correct |
50 | Correct | 5 ms | 5248 KB | Output is correct |
51 | Correct | 4 ms | 5248 KB | Output is correct |
52 | Correct | 5 ms | 5120 KB | Output is correct |
53 | Correct | 5 ms | 5120 KB | Output is correct |
54 | Correct | 4 ms | 5120 KB | Output is correct |
55 | Correct | 4 ms | 5120 KB | Output is correct |
56 | Correct | 4 ms | 5120 KB | Output is correct |
57 | Correct | 5 ms | 5248 KB | Output is correct |
58 | Correct | 5 ms | 5120 KB | Output is correct |
59 | Correct | 4 ms | 5120 KB | Output is correct |
60 | Correct | 4 ms | 5248 KB | Output is correct |
61 | Correct | 4 ms | 5120 KB | Output is correct |
62 | Correct | 4 ms | 5248 KB | Output is correct |
63 | Correct | 5 ms | 5120 KB | Output is correct |
64 | Correct | 180 ms | 16864 KB | Output is correct |
65 | Correct | 180 ms | 16824 KB | Output is correct |
66 | Correct | 182 ms | 16804 KB | Output is correct |
67 | Correct | 186 ms | 16796 KB | Output is correct |
68 | Correct | 176 ms | 16804 KB | Output is correct |
69 | Correct | 179 ms | 16820 KB | Output is correct |
70 | Correct | 184 ms | 16744 KB | Output is correct |
71 | Correct | 178 ms | 16784 KB | Output is correct |
72 | Correct | 177 ms | 16820 KB | Output is correct |
73 | Correct | 196 ms | 26832 KB | Output is correct |
74 | Correct | 195 ms | 26808 KB | Output is correct |
75 | Correct | 176 ms | 16696 KB | Output is correct |
76 | Correct | 172 ms | 16720 KB | Output is correct |
77 | Correct | 188 ms | 16692 KB | Output is correct |
78 | Correct | 186 ms | 16756 KB | Output is correct |
79 | Correct | 185 ms | 16700 KB | Output is correct |
80 | Correct | 184 ms | 16696 KB | Output is correct |
81 | Correct | 145 ms | 17140 KB | Output is correct |
82 | Correct | 164 ms | 16888 KB | Output is correct |
83 | Correct | 187 ms | 20924 KB | Output is correct |
84 | Correct | 191 ms | 22596 KB | Output is correct |
85 | Correct | 187 ms | 22340 KB | Output is correct |
86 | Correct | 179 ms | 17848 KB | Output is correct |
87 | Correct | 176 ms | 17468 KB | Output is correct |
88 | Correct | 163 ms | 17908 KB | Output is correct |
89 | Correct | 167 ms | 17864 KB | Output is correct |
90 | Correct | 180 ms | 17824 KB | Output is correct |
91 | Correct | 169 ms | 17948 KB | Output is correct |
92 | Correct | 170 ms | 18228 KB | Output is correct |
93 | Correct | 167 ms | 20100 KB | Output is correct |
94 | Correct | 166 ms | 21616 KB | Output is correct |
95 | Correct | 153 ms | 20336 KB | Output is correct |
96 | Correct | 166 ms | 18980 KB | Output is correct |
97 | Correct | 167 ms | 17684 KB | Output is correct |
98 | Correct | 159 ms | 17512 KB | Output is correct |
99 | Correct | 168 ms | 17204 KB | Output is correct |
100 | Correct | 162 ms | 19808 KB | Output is correct |
101 | Correct | 170 ms | 18228 KB | Output is correct |
102 | Correct | 158 ms | 17540 KB | Output is correct |
103 | Correct | 173 ms | 17368 KB | Output is correct |
104 | Correct | 101 ms | 17644 KB | Output is correct |
105 | Correct | 201 ms | 24376 KB | Output is correct |
106 | Correct | 99 ms | 17516 KB | Output is correct |
107 | Correct | 104 ms | 17508 KB | Output is correct |
108 | Correct | 198 ms | 27576 KB | Output is correct |
109 | Correct | 100 ms | 17644 KB | Output is correct |
110 | Correct | 198 ms | 27704 KB | Output is correct |
111 | Correct | 164 ms | 16712 KB | Output is correct |