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 <bits/stdc++.h>
using namespace std;
int solve(int N, int M, vector<int> F, vector<vector<int>> S) {
vector<int> cnt_S(N);
vector<int> cnt_ch(N);
vector<bool> flag(N);
for (int i = 1; i < N; i++) {
cnt_ch[F[i]]++;
}
int cnt_bad = 0;
int res = 0;
for (int i = 0; i < N - 1; i++) {
for (int j = 0; j < M; j++) {
int u = S[j][i];
cnt_bad -= (cnt_S[u] != 0 && cnt_S[u] != M);
cnt_S[u]++;
cnt_bad += (cnt_S[u] != 0 && cnt_S[u] != M);
}
int u = S[0][i];
cnt_bad -= (flag[F[u]] && cnt_ch[F[u]] > 0);
flag[u] = true;
cnt_ch[F[u]]--;
cnt_bad += (flag[F[u]] && cnt_ch[F[u]] > 0);
cnt_bad += (flag[u] && cnt_ch[u] > 0);
if (cnt_bad == 0) {
res++;
}
}
return res;
}
# | 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... |