# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1081752 | SugarCubes69 | September (APIO24_september) | C++17 | 199 ms | 21964 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 <bits/stdc++.h>
using namespace std;
int deg[100005];
int fst[100005],lst[100005];
vector<int> adj[100005];
void dfs(int x){
for(int child:adj[x]){
dfs(child);
lst[x] = max(lst[x],lst[child]);
}
}
int solve(int n, int m, vector<int> P, vector<vector<int> > a)
{
for(int i=0;i<n;i++) adj[i].clear();
for(int i=1;i<n;i++) adj[P[i]].push_back(i);
fill(fst,fst+n,n);
memset(lst,0,sizeof(lst));
for(int i=0;i<m;i++) for(int j=0;j<n-1;j++){
fst[a[i][j]] = min(fst[a[i][j]],j);
lst[a[i][j]] = max(lst[a[i][j]],j);
}
dfs(0);
vector<pair<int,int> > intervals;
for(int i=1;i<n;i++) intervals.push_back(pair<int,int>(fst[i],lst[i]));
sort(intervals.begin(),intervals.end());
int ans = 0;
int bak = -1;
for(int i=0;i<intervals.size();i++){
if(bak < intervals[i].first){
ans++;
}
bak = max(bak,intervals[i].second);
}
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... |