# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1081362 | SugarCubes69 | September (APIO24_september) | C++17 | 3 ms | 3676 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;
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=0;i<N-1;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;
}
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... |