Submission #1177868

#TimeUsernameProblemLanguageResultExecution timeMemory
1177868trashaccountSeptember (APIO24_september)C++20
55 / 100
1095 ms11056 KiB
#include "september.h"
#include <bits/stdc++.h>
using namespace std;

const int NM = 1e5;

int N, M;
vector <int> son[NM+5];
int timer, tin[NM+5], tout[NM+5];
int sum[NM+5], res[NM+5];

void dfs(int u){
	tin[u] = ++timer;
	for (int v : son[u]) dfs(v);
	tout[u] = timer;
}

bool is_ancestor(int u, int v){
	return tin[u] <= tin[v] && tout[u] >= tout[v];
}

int solve(int _N, int _M, vector <int> F, vector <vector <int> > S){
	N = _N, M = _M;
	for (int i = 0; i < N; i++) son[i].clear();
	for (int i = 1; i < N; i++){
		int p = F[i];
		son[p].push_back(i);
	}
	timer = 0;
	dfs(0);

	for (int i = 0; i < M; i++){
		for (int j = 0; j < N; j++) sum[j] = 0;
		for (int j = 0; j < N-1; j++)
			for (int k = j+1; k < N-1; k++)
				if (is_ancestor(S[i][j], S[i][k]) || (i > 0 && res[S[i][j]] >= res[S[i][k]])) sum[j]++, sum[k]--;

		res[S[i][0]] = 1;
		for (int j = 0; j+1 < N-1; j++){
			if (j > 0) sum[j] += sum[j-1];
			if (sum[j] > 0) res[S[i][j+1]] = res[S[i][j]];
			else res[S[i][j+1]] = res[S[i][j]]+1;
		}
	}
	int mx = 0;
	for (int i = 1; i < N; i++) mx = max(mx, res[i]);
	return mx;
}
#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...