# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
997038 | huutuan | September (APIO24_september) | C++17 | 145 ms | 15164 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |