제출 #1201232

#제출 시각아이디문제언어결과실행 시간메모리
1201232browntoad9월 (APIO24_september)C++20
100 / 100
114 ms19976 KiB
#include "september.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n) 
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())

namespace{
	const ll maxn = 1e5+5;
	const ll mod = 1e9+7;
	const ll inf = 1ll<<60;

	int n, m;
	vector<vector<int>> seq;
	vector<int> pos[maxn]; // for each node, its id in the sequence
	int mxid;

	vector<int> g[maxn];
	vector<int> occ(maxn);
}

void dfs(int u){
	if (occ[u]) return;
	REP(i, m) mxid = max(mxid, pos[u][i]);
	occ[u] = 1;
	for (auto v:g[u]){
		dfs(v);
	}
}
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
	n = N; m = M;
	mxid = -1;
	seq = S;
	REP(i, n) g[i].clear();
	REP(i, n) occ[i] = 0;

	REP1(i, n-1){
		g[F[i]].pb(i);
	}
	REP(i, n) pos[i].clear();
	REP(i, m){
		REP(j, n-1){
			pos[S[i][j]].pb(j);
		}
	}

	int ret = 0;
	REP(j, n-1){
		if (mxid < j){
			ret++;
			REP(i, m){
				dfs(seq[i][j]); 
			}
		}
		else{
			REP(i, m) dfs(seq[i][j]);
		}
	}
	return ret;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...