Submission #1087540

# Submission time Handle Problem Language Result Execution time Memory
1087540 2024-09-12T21:36:44 Z veehj September (APIO24_september) C++17
100 / 100
148 ms 16580 KB
// #include "september.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (ll) a.size()
#define all(x) (x).begin(), (x).end()
vector<int> vist, nchild, pa;
set<int> call, tagged;
vector<vector<int>> child;

void pop(int nw){
  if(nchild[nw]!=0 || nw==0 || !tagged.count(nw)) return;
  tagged.erase(nw);
  nchild[pa[nw]]--;
  pop(pa[nw]);
}

int solve(int n, int m, std::vector<int> f, std::vector<std::vector<int>> s) {
  int ans=0;
  pa=f;
  vist.assign(n, 0);
  nchild.assign(n, 0);
  call={}; tagged={};
  child.assign(n, vector<int>(0));
  for(int i=1; i<n; i++){
    child[pa[i]].pb(i);
    nchild[pa[i]]++;
  }
  for(int i=0; i<n-1; i++){
    for(int j=0; j<m; j++){
      vist[s[j][i]]++;
      if(vist[s[j][i]]!=m){ call.insert(s[j][i]); continue; }
      call.erase(s[j][i]);
	  tagged.insert(s[j][i]);
      if(nchild[s[j][i]]==0) pop(s[j][i]);
    }
    ans+=(tagged.empty() && call.empty());
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 496 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 496 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 126 ms 16520 KB Output is correct
5 Correct 124 ms 15824 KB Output is correct
6 Correct 119 ms 15768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 496 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 126 ms 16520 KB Output is correct
19 Correct 124 ms 15824 KB Output is correct
20 Correct 119 ms 15768 KB Output is correct
21 Correct 146 ms 16056 KB Output is correct
22 Correct 147 ms 15800 KB Output is correct
23 Correct 130 ms 16564 KB Output is correct
24 Correct 130 ms 16568 KB Output is correct
25 Correct 148 ms 15824 KB Output is correct
26 Correct 140 ms 16056 KB Output is correct
27 Correct 139 ms 16580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 126 ms 16520 KB Output is correct
8 Correct 124 ms 15824 KB Output is correct
9 Correct 119 ms 15768 KB Output is correct
10 Correct 76 ms 15968 KB Output is correct
11 Correct 70 ms 16072 KB Output is correct
12 Correct 67 ms 15924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 496 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 126 ms 16520 KB Output is correct
36 Correct 124 ms 15824 KB Output is correct
37 Correct 119 ms 15768 KB Output is correct
38 Correct 146 ms 16056 KB Output is correct
39 Correct 147 ms 15800 KB Output is correct
40 Correct 130 ms 16564 KB Output is correct
41 Correct 130 ms 16568 KB Output is correct
42 Correct 148 ms 15824 KB Output is correct
43 Correct 140 ms 16056 KB Output is correct
44 Correct 139 ms 16580 KB Output is correct
45 Correct 76 ms 15968 KB Output is correct
46 Correct 70 ms 16072 KB Output is correct
47 Correct 67 ms 15924 KB Output is correct
48 Correct 80 ms 14368 KB Output is correct
49 Correct 85 ms 14444 KB Output is correct
50 Correct 75 ms 14920 KB Output is correct
51 Correct 87 ms 15004 KB Output is correct
52 Correct 75 ms 14336 KB Output is correct
53 Correct 72 ms 14284 KB Output is correct
54 Correct 79 ms 14796 KB Output is correct