Submission #421571

# Submission time Handle Problem Language Result Execution time Memory
421571 2021-06-09T09:17:22 Z Keshi Werewolf (IOI18_werewolf) C++17
15 / 100
4000 ms 150256 KB
//In the name of God
#include <bits/stdc++.h>
#include "werewolf.h"
using namespace std;

typedef int ll;
typedef pair<ll, ll> pll;

const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e9;

#define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()

int n, m, q;
int dsu[maxn];
vector<int> g[maxn], vec[maxn], h[maxn];
vector<pll> com[maxn];
map<ll, ll> mp[maxn];

void init(bool f = 1){
	for(ll i = 0; i < n; i++){
		dsu[i] = i;
		vec[i].reserve(10);
		vec[i].pb(i);
		if(f) mp[i][i] = n;
		if(f) com[i].pb(Mp(i, n));
	}
}
bool Union(ll v, ll u, ll i){
	v = dsu[v];
	u = dsu[u];
	if(v == u) return 0;
	if(Sz(vec[v]) < Sz(vec[u])) swap(v, u);
	for(ll x : vec[u]){
		vec[v].pb(x);
		dsu[x] = v;
		mp[x][v] = i;
		com[x].pb(Mp(v, i));
	}
	vec[u].clear();
	vec[u].shrink_to_fit();
	return 1;
}
bool merge(ll v, ll u){
	v = dsu[v];
	u = dsu[u];
	if(v == u) return 0;
	if(Sz(vec[v]) < Sz(vec[u])) swap(v, u);
	for(ll x : vec[u]){
		vec[v].pb(x);
		dsu[x] = v;
	}
	for(pll x : mp[u]){
		mp[v][x.F] = max(mp[v][x.F], x.S);
	}
	mp[u].clear();
	vec[u].clear();
	vec[u].shrink_to_fit();
	return 1;
}

vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R){
	m = Sz(X);
	q = Sz(S);
	n = N;
	init();
	for(ll i = 0; i < m; i++){
		g[X[i]].pb(Y[i]);
		g[Y[i]].pb(X[i]);
	}
	for(ll i = 0; i < q; i++){
		h[R[i]].pb(i);
	}
	for(ll i = n; i--;){
		for(ll j : g[i]){
			if(j >= i) Union(i, j, i);
		}
	}
	init(0);
	vector<int> ans(q);
	for(ll i = 0; i < n; i++){
		for(ll j : g[i]){
			if(j > i) continue;
//			cout << "^ " << i << " " << j << "\n";
			merge(i, j);
		}
		for(ll j : h[i]){
			ll mx = 0;
			ll e = dsu[E[j]];
			for(pll x : com[S[j]]){
//				cout << "! " << x.F << " " << x.S << " " << mp[e][x.F] << "\n";
				mx = max(mx, min(x.S, mp[e][x.F]));
			}
//			cout << j << " -> " << mx << "\n";
			if(mx >= L[j]) ans[j] = 1;
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 28420 KB Output is correct
2 Correct 16 ms 28472 KB Output is correct
3 Correct 15 ms 28464 KB Output is correct
4 Correct 15 ms 28392 KB Output is correct
5 Correct 16 ms 28492 KB Output is correct
6 Correct 16 ms 28484 KB Output is correct
7 Correct 16 ms 28448 KB Output is correct
8 Correct 15 ms 28492 KB Output is correct
9 Correct 16 ms 28492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 28420 KB Output is correct
2 Correct 16 ms 28472 KB Output is correct
3 Correct 15 ms 28464 KB Output is correct
4 Correct 15 ms 28392 KB Output is correct
5 Correct 16 ms 28492 KB Output is correct
6 Correct 16 ms 28484 KB Output is correct
7 Correct 16 ms 28448 KB Output is correct
8 Correct 15 ms 28492 KB Output is correct
9 Correct 16 ms 28492 KB Output is correct
10 Correct 25 ms 29464 KB Output is correct
11 Correct 26 ms 29644 KB Output is correct
12 Correct 33 ms 30044 KB Output is correct
13 Correct 24 ms 29644 KB Output is correct
14 Correct 27 ms 29872 KB Output is correct
15 Correct 28 ms 29644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4083 ms 150256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 28420 KB Output is correct
2 Correct 16 ms 28472 KB Output is correct
3 Correct 15 ms 28464 KB Output is correct
4 Correct 15 ms 28392 KB Output is correct
5 Correct 16 ms 28492 KB Output is correct
6 Correct 16 ms 28484 KB Output is correct
7 Correct 16 ms 28448 KB Output is correct
8 Correct 15 ms 28492 KB Output is correct
9 Correct 16 ms 28492 KB Output is correct
10 Correct 25 ms 29464 KB Output is correct
11 Correct 26 ms 29644 KB Output is correct
12 Correct 33 ms 30044 KB Output is correct
13 Correct 24 ms 29644 KB Output is correct
14 Correct 27 ms 29872 KB Output is correct
15 Correct 28 ms 29644 KB Output is correct
16 Execution timed out 4083 ms 150256 KB Time limit exceeded
17 Halted 0 ms 0 KB -