이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "september.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn = 100005;
ll fst[maxn];
ll lst[maxn];
vector<ll> adj[maxn];
void dfs(ll x){
for(ll child:adj[x]){
dfs(child);
lst[x] = max(lst[x],lst[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}}));
}*/
컴파일 시 표준 에러 (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... |