제출 #1151194

#제출 시각아이디문제언어결과실행 시간메모리
1151194TroySer9월 (APIO24_september)C++20
73 / 100
1096 ms53256 KiB
#include "september.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int solve(int N, int M, vector<int> F, vector<vector<int> > S) {

	vector<vector<ll> > adjList;
	adjList.resize(N);

	for (ll i = 1; i < N; i++) {
		adjList[F[i]].push_back(i);
	}

	set<ll> beenBanished;
	vector<int> firstS = S[0];

	vector<map<ll, ll> > actualIndices(M);
	for(ll i = 0; i < M; i++) {
		for (ll j = 0; j < N - 1; j++) {
			actualIndices[i][S[i][j]] = j;
		}
	}

	map<ll, ll> actualIndex;
	for (ll i = 1; i < N; i++) {
		actualIndex[i] = 0;
		for (ll j = 0; j < M; j++) {
			actualIndex[i] = max(actualIndices[j][i], actualIndex[i]);
		}
	}

	ll banishmentIndex = 0;
	ll maxK = 1;

	for (ll i = 0; i < N - 1; i++) {

		// cout << firstS[i] << " " << i << ", " << banishmentIndex << endl;

		if (banishmentIndex < i) {
			maxK++;
		}

		queue<ll> bfsQueue;
		for (ll j = 0; j < M; j++) {
			bfsQueue.push(S[j][i]);
		}

		while (!bfsQueue.empty()) {

			ll currentIndex = bfsQueue.front();
			bfsQueue.pop();
			if (beenBanished.find(currentIndex) != beenBanished.end()) {
				continue;
			}

			beenBanished.insert(currentIndex);
			banishmentIndex = max(banishmentIndex, actualIndex[currentIndex]);

			for (ll v: adjList[currentIndex]) {
				bfsQueue.push(v);
			}

		}

	}

	return maxK;

}
#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...