답안 #771065

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771065 2023-07-02T12:12:18 Z khshg 늑대인간 (IOI18_werewolf) C++14
15 / 100
4000 ms 38080 KB
#include "werewolf.h"
#include<bits/stdc++.h>
using namespace std;

int N;
vector<vector<int>> adj;
vector<int> D;
vector<pair<int, int>> ch;

void init(int N) {
	D = vector<int>(N); iota(begin(D), end(D), 0);
	ch.resize(N);
}

int parent(int x) {
	return (D[x] == x ? x : D[x] = parent(D[x]));
}

void unite(int x, int y) {
	x = parent(x); y = parent(y);
	if(x == y) return;
	int s = (int)D.size();
	D[x] = D[y] = s;
	D.push_back(s);
	ch.emplace_back(x, y);
}

void dfs(int S, int& tim3) {
	if(S < N) {
		ch[S] = {tim3, tim3};
		++tim3;
		return;
	}
	int x, y;
	tie(x, y) = ch[S];
	dfs(x, tim3); dfs(y, tim3);
	ch[S].first = min(ch[x].first, ch[y].first);
	ch[S].second = max(ch[x].second, ch[y].second);
}
 
vector<int> check_validity(int _N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
	N = _N;
	adj.resize(N);
	int M = (int)X.size();
	for(int i = 0; i < M; ++i) {
		adj[X[i]].push_back(Y[i]);
		adj[Y[i]].push_back(X[i]);
	}
	int Q = (int)L.size();
	vector<pair<int, int>> RL(Q), RR(Q), pos(N);
	{
		vector<int> sind(Q);
		iota(begin(sind), end(sind), 0);
		sort(begin(sind), end(sind), [&](const int& i, const int& j) { return L[i] > L[j]; });
		init(N);
		vector<int> par(Q);
		int i = N - 1;
		for(int j = 0; j < Q; ++j) {
			for(; i >= L[sind[j]]; --i) {
				for(auto& u : adj[i]) {
					if(u >= i) unite(u, i);
				}
			}
			par[sind[j]] = parent(S[sind[j]]);
		}
		for(; i >= 0; --i) {
			for(auto& u : adj[i]) {
				if(u >= i) unite(u, i);
			}
		}
		int tim3 = 0; dfs((int)D.size() - 1, tim3);
		for(int i = 0; i < Q; ++i) {
			RL[i] = ch[par[i]];
		}
		for(int i = 0; i < N; ++i) {
			pos[i].first = ch[i].first;
		}
	}
	{
		vector<int> sind(Q);
		iota(begin(sind), end(sind), 0);
		sort(begin(sind), end(sind), [&](const int& i, const int& j) { return R[i] < R[j]; });
		init(N);
		vector<int> par(Q);
		int i = 0;
		for(int j = 0; j < Q; ++j) {
			for(; i <= R[sind[j]]; ++i) {
				for(auto& u : adj[i]) {
					if(u <= i) unite(u, i);
				}
			}
			par[sind[j]] = parent(E[sind[j]]);
		}
		for(; i < N; ++i) {
			for(auto& u : adj[i]) {
				if(u <= i) unite(u, i);
			}
		}
		int tim3 = 0; dfs((int)D.size() - 1, tim3);
		for(int i = 0; i < Q; ++i) {
			RR[i] = ch[par[i]];
		}
		for(int i = 0; i < N; ++i) {
			pos[i].second = ch[i].first;
		}
	}
	vector<int> ans(Q);
	for(int i = 0; i < Q; ++i) {
		for(auto& u : pos) {
			if(RL[i].first <= u.first && u.first <= RL[i].second && RR[i].first <= u.second && u.second <= RR[i].second) {
				ans[i] = 1;
				break;
			}
		}
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 11 ms 976 KB Output is correct
11 Correct 15 ms 852 KB Output is correct
12 Correct 26 ms 896 KB Output is correct
13 Correct 10 ms 1056 KB Output is correct
14 Correct 12 ms 952 KB Output is correct
15 Correct 16 ms 1048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4021 ms 38080 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 11 ms 976 KB Output is correct
11 Correct 15 ms 852 KB Output is correct
12 Correct 26 ms 896 KB Output is correct
13 Correct 10 ms 1056 KB Output is correct
14 Correct 12 ms 952 KB Output is correct
15 Correct 16 ms 1048 KB Output is correct
16 Execution timed out 4021 ms 38080 KB Time limit exceeded
17 Halted 0 ms 0 KB -