Submission #997038

# Submission time Handle Problem Language Result Execution time Memory
997038 2024-06-11T15:53:59 Z huutuan September (APIO24_september) C++17
100 / 100
145 ms 15164 KB
#include "september.h"

#include <vector>

#include <bits/stdc++.h>

using namespace std;

const int N=1e5+10;
bool is_equal[N], check[N], ss[N], vis[N];
int par[N], cnt[N];
int a[5][N], n, m;
vector<int> g[N];

int solve(int N_, int M, vector<int> F, vector<vector<int>> S) {
   n=N_, m=M;
   for (int i=0; i<m; ++i) for (int j=1; j<n; ++j) a[i][j]=S[i][j-1]+1;
   for (int i=1; i<=n; ++i) par[i]=F[i-1]+1, g[par[i]].push_back(i);
   int sum=0;
   for (int i=1; i<n; ++i){
      int u=a[0][i];
      if (vis[par[u]]) --sum, ss[u]=0;
      for (int v:g[u]){
         if (!vis[v]) ss[v]=1, ++sum;
      }
      vis[u]=1;
      check[i]=!sum;
      is_equal[i]=1;
   }
   for (int j=1; j<m; ++j){
      sum=0;
      for (int i=1; i<n; ++i){
         if (a[0][i]!=a[j][i]){
            sum-=!!cnt[a[0][i]];
            sum-=!!cnt[a[j][i]];
            ++cnt[a[0][i]]; --cnt[a[j][i]];
            sum+=!!cnt[a[0][i]];
            sum+=!!cnt[a[j][i]];
         }
         is_equal[i]&=!sum;
      }
   }
   int ans=0;
   for (int i=1; i<n; ++i) ans+=check[i] && is_equal[i];
   for (int i=0; i<=n; ++i){
      g[i].clear();
      ss[i]=vis[i]=cnt[i]=0;
   }
   return ans;
}

Compilation message

september.cpp: In function 'int solve(int, int, std::vector<int>, std::vector<std::vector<int> >)':
september.cpp:47:26: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   47 |       ss[i]=vis[i]=cnt[i]=0;
      |                    ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 2 ms 4528 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 1 ms 4784 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 2 ms 4700 KB Output is correct
14 Correct 2 ms 4700 KB Output is correct
15 Correct 2 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4784 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 2 ms 4528 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 2 ms 4700 KB Output is correct
17 Correct 1 ms 4784 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 2 ms 4700 KB Output is correct
21 Correct 2 ms 4700 KB Output is correct
22 Correct 2 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 2 ms 4700 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 2 ms 4700 KB Output is correct
29 Correct 2 ms 4700 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 2 ms 4700 KB Output is correct
34 Correct 2 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4784 KB Output is correct
4 Correct 91 ms 13364 KB Output is correct
5 Correct 97 ms 13468 KB Output is correct
6 Correct 95 ms 13404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 1 ms 4784 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 2 ms 4700 KB Output is correct
14 Correct 2 ms 4700 KB Output is correct
15 Correct 2 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 2 ms 4700 KB Output is correct
18 Correct 91 ms 13364 KB Output is correct
19 Correct 97 ms 13468 KB Output is correct
20 Correct 95 ms 13404 KB Output is correct
21 Correct 103 ms 13488 KB Output is correct
22 Correct 120 ms 12480 KB Output is correct
23 Correct 101 ms 14032 KB Output is correct
24 Correct 145 ms 13996 KB Output is correct
25 Correct 101 ms 13660 KB Output is correct
26 Correct 105 ms 13488 KB Output is correct
27 Correct 101 ms 11608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4784 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 91 ms 13364 KB Output is correct
8 Correct 97 ms 13468 KB Output is correct
9 Correct 95 ms 13404 KB Output is correct
10 Correct 60 ms 14024 KB Output is correct
11 Correct 83 ms 14240 KB Output is correct
12 Correct 61 ms 15164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4696 KB Output is correct
9 Correct 1 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 1 ms 4700 KB Output is correct
12 Correct 2 ms 4528 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 2 ms 4700 KB Output is correct
17 Correct 1 ms 4784 KB Output is correct
18 Correct 1 ms 4700 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 2 ms 4700 KB Output is correct
21 Correct 2 ms 4700 KB Output is correct
22 Correct 2 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 2 ms 4700 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 2 ms 4700 KB Output is correct
29 Correct 2 ms 4700 KB Output is correct
30 Correct 2 ms 4700 KB Output is correct
31 Correct 2 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 2 ms 4700 KB Output is correct
34 Correct 2 ms 4700 KB Output is correct
35 Correct 91 ms 13364 KB Output is correct
36 Correct 97 ms 13468 KB Output is correct
37 Correct 95 ms 13404 KB Output is correct
38 Correct 103 ms 13488 KB Output is correct
39 Correct 120 ms 12480 KB Output is correct
40 Correct 101 ms 14032 KB Output is correct
41 Correct 145 ms 13996 KB Output is correct
42 Correct 101 ms 13660 KB Output is correct
43 Correct 105 ms 13488 KB Output is correct
44 Correct 101 ms 11608 KB Output is correct
45 Correct 60 ms 14024 KB Output is correct
46 Correct 83 ms 14240 KB Output is correct
47 Correct 61 ms 15164 KB Output is correct
48 Correct 61 ms 14028 KB Output is correct
49 Correct 62 ms 13800 KB Output is correct
50 Correct 56 ms 13512 KB Output is correct
51 Correct 57 ms 14288 KB Output is correct
52 Correct 71 ms 13972 KB Output is correct
53 Correct 62 ms 13776 KB Output is correct
54 Correct 58 ms 14420 KB Output is correct