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;
typedef long long int ll;
const ll maxn = 100001;
ll fst[maxn];
ll lst[maxn];
vector<ll> adj[maxn];
void dfs(ll x){
for(ll child:adj[x]){
fst[child] = min(fst[child],fst[x]);
dfs(child);
}
}
vector<array<ll,2>> intervals;
ll ans = 0;
ll bak = 0;
int solve(int N, int M, vector<int> F,vector<vector<int>> S){
for(int i=0;i<N;i++) adj[i].clear();
for(int i=1;i<N;i++) adj[F[i]].push_back(i);
fill(fst,fst+N,INT_MAX);
memset(lst,0,sizeof(lst));
for(int i=0;i<M;i++) for(ll j=0;j<N;j++){
fst[S[i][j]] = min(fst[S[i][j]],j);
lst[S[i][j]] = max(lst[S[i][j]],j);
}
dfs(0);
intervals.clear();
for(int i=1;i<N;i++) intervals.push_back({fst[i],lst[i]});
sort(intervals.begin(),intervals.end());
ans = 0;
bak = -1;
for(int i=0;i<intervals.size();i++){
if(bak < intervals[i][0]){
ans++;
}
bak = max(bak,intervals[i][1]);
}
return ans;
}
/*int main(){
printf("%lld\n",solve(5, 2, {-1, 0, 0, 1, 1}, {{1, 2, 3, 4}, {4, 1, 2, 3}}));
}*/
Compilation message (stderr)
september.cpp: In function 'int solve(int, int, std::vector<int>, std::vector<std::vector<int> >)':
september.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<intervals.size();i++){
| ~^~~~~~~~~~~~~~~~~
# | 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... |