답안 #473787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
473787 2021-09-16T08:55:29 Z Lain Power Plant (JOI20_power) C++17
100 / 100
212 ms 34372 KB
#include "bits/stdc++.h"
using namespace std;

template<class Fun>
class y_combinator_result {
  Fun fun_;
public:
  template<class T>
  explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
 
  template<class ...Args>
  decltype(auto) operator()(Args &&...args) {
    return fun_(std::ref(*this), std::forward<Args>(args)...);
  }
};
 
template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
  return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

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

  int n;
  cin >> n;
  vector<vector<int>> g(n);
  for (int i = 0; i < n-1; i++) {
    int u,v;
    cin >> u >> v;
    u--,v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  string gen;
  cin >> gen;

  vector<int> dp(n);
  int ans = 0;
  y_combinator([&](auto self, int s, int p)->void {
    vector<int> c;
    for (auto& u : g[s]){
      if (u==p) continue;
      self(u,s);
      c.push_back(dp[u]);
    }
    if (gen[s] == '0') {
      for (auto& x : c) dp[s] += x;
    }
    else {
      if (c.size() == 0)
        dp[s] = 1;
      else {
        ans = max(ans,*max_element(c.begin(),c.end())+1);
        for (auto& x : c)
          dp[s] += x;
        dp[s]--;
        dp[s] = max(dp[s],1);
      }
    }
    ans = max(dp[s],ans);
  })(0,-1);
  cout << ans << '\n';
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 2 ms 332 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 2 ms 460 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 460 KB Output is correct
50 Correct 1 ms 460 KB Output is correct
51 Correct 1 ms 424 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
54 Correct 2 ms 460 KB Output is correct
55 Correct 1 ms 460 KB Output is correct
56 Correct 1 ms 460 KB Output is correct
57 Correct 2 ms 588 KB Output is correct
58 Correct 1 ms 460 KB Output is correct
59 Correct 1 ms 392 KB Output is correct
60 Correct 1 ms 460 KB Output is correct
61 Correct 1 ms 460 KB Output is correct
62 Correct 1 ms 588 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 452 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 2 ms 460 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 2 ms 332 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 460 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 2 ms 460 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 460 KB Output is correct
50 Correct 1 ms 460 KB Output is correct
51 Correct 1 ms 424 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
54 Correct 2 ms 460 KB Output is correct
55 Correct 1 ms 460 KB Output is correct
56 Correct 1 ms 460 KB Output is correct
57 Correct 2 ms 588 KB Output is correct
58 Correct 1 ms 460 KB Output is correct
59 Correct 1 ms 392 KB Output is correct
60 Correct 1 ms 460 KB Output is correct
61 Correct 1 ms 460 KB Output is correct
62 Correct 1 ms 588 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 172 ms 15220 KB Output is correct
65 Correct 183 ms 15140 KB Output is correct
66 Correct 149 ms 15216 KB Output is correct
67 Correct 190 ms 15484 KB Output is correct
68 Correct 151 ms 15152 KB Output is correct
69 Correct 162 ms 15216 KB Output is correct
70 Correct 165 ms 15124 KB Output is correct
71 Correct 159 ms 15116 KB Output is correct
72 Correct 167 ms 15140 KB Output is correct
73 Correct 185 ms 32900 KB Output is correct
74 Correct 212 ms 32944 KB Output is correct
75 Correct 165 ms 15020 KB Output is correct
76 Correct 151 ms 14984 KB Output is correct
77 Correct 151 ms 15016 KB Output is correct
78 Correct 165 ms 15176 KB Output is correct
79 Correct 155 ms 15056 KB Output is correct
80 Correct 173 ms 15000 KB Output is correct
81 Correct 152 ms 16212 KB Output is correct
82 Correct 191 ms 15688 KB Output is correct
83 Correct 181 ms 22668 KB Output is correct
84 Correct 170 ms 25872 KB Output is correct
85 Correct 208 ms 25488 KB Output is correct
86 Correct 168 ms 17180 KB Output is correct
87 Correct 160 ms 16256 KB Output is correct
88 Correct 169 ms 16716 KB Output is correct
89 Correct 163 ms 16624 KB Output is correct
90 Correct 142 ms 16300 KB Output is correct
91 Correct 170 ms 16636 KB Output is correct
92 Correct 148 ms 17124 KB Output is correct
93 Correct 149 ms 20992 KB Output is correct
94 Correct 158 ms 23440 KB Output is correct
95 Correct 167 ms 21352 KB Output is correct
96 Correct 148 ms 18672 KB Output is correct
97 Correct 149 ms 16428 KB Output is correct
98 Correct 199 ms 15768 KB Output is correct
99 Correct 159 ms 15472 KB Output is correct
100 Correct 153 ms 20116 KB Output is correct
101 Correct 171 ms 17152 KB Output is correct
102 Correct 149 ms 16000 KB Output is correct
103 Correct 144 ms 15816 KB Output is correct
104 Correct 97 ms 17716 KB Output is correct
105 Correct 191 ms 28412 KB Output is correct
106 Correct 84 ms 17460 KB Output is correct
107 Correct 91 ms 17592 KB Output is correct
108 Correct 187 ms 33872 KB Output is correct
109 Correct 129 ms 17720 KB Output is correct
110 Correct 202 ms 34372 KB Output is correct
111 Correct 166 ms 15208 KB Output is correct