# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
421578 |
2021-06-09T09:23:19 Z |
Keshi |
Werewolf (IOI18_werewolf) |
C++17 |
|
4000 ms |
150008 KB |
//In the name of God
#include <bits/stdc++.h>
#include "werewolf.h"
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
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(i >= j) merge(i, j);
}
for(ll j : h[i]){
ll mx = 0;
ll e = dsu[E[j]];
for(pll x : com[S[j]]){
mx = max(mx, min(x.S, mp[e][x.F]));
}
if(mx >= L[j]) ans[j] = 1;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
28508 KB |
Output is correct |
2 |
Correct |
18 ms |
28488 KB |
Output is correct |
3 |
Correct |
16 ms |
28508 KB |
Output is correct |
4 |
Correct |
16 ms |
28492 KB |
Output is correct |
5 |
Correct |
16 ms |
28492 KB |
Output is correct |
6 |
Correct |
20 ms |
28500 KB |
Output is correct |
7 |
Correct |
16 ms |
28416 KB |
Output is correct |
8 |
Correct |
19 ms |
28492 KB |
Output is correct |
9 |
Correct |
16 ms |
28408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
28508 KB |
Output is correct |
2 |
Correct |
18 ms |
28488 KB |
Output is correct |
3 |
Correct |
16 ms |
28508 KB |
Output is correct |
4 |
Correct |
16 ms |
28492 KB |
Output is correct |
5 |
Correct |
16 ms |
28492 KB |
Output is correct |
6 |
Correct |
20 ms |
28500 KB |
Output is correct |
7 |
Correct |
16 ms |
28416 KB |
Output is correct |
8 |
Correct |
19 ms |
28492 KB |
Output is correct |
9 |
Correct |
16 ms |
28408 KB |
Output is correct |
10 |
Correct |
26 ms |
29560 KB |
Output is correct |
11 |
Correct |
27 ms |
29588 KB |
Output is correct |
12 |
Correct |
33 ms |
29980 KB |
Output is correct |
13 |
Correct |
25 ms |
29644 KB |
Output is correct |
14 |
Correct |
29 ms |
29896 KB |
Output is correct |
15 |
Correct |
28 ms |
29648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4062 ms |
150008 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
28508 KB |
Output is correct |
2 |
Correct |
18 ms |
28488 KB |
Output is correct |
3 |
Correct |
16 ms |
28508 KB |
Output is correct |
4 |
Correct |
16 ms |
28492 KB |
Output is correct |
5 |
Correct |
16 ms |
28492 KB |
Output is correct |
6 |
Correct |
20 ms |
28500 KB |
Output is correct |
7 |
Correct |
16 ms |
28416 KB |
Output is correct |
8 |
Correct |
19 ms |
28492 KB |
Output is correct |
9 |
Correct |
16 ms |
28408 KB |
Output is correct |
10 |
Correct |
26 ms |
29560 KB |
Output is correct |
11 |
Correct |
27 ms |
29588 KB |
Output is correct |
12 |
Correct |
33 ms |
29980 KB |
Output is correct |
13 |
Correct |
25 ms |
29644 KB |
Output is correct |
14 |
Correct |
29 ms |
29896 KB |
Output is correct |
15 |
Correct |
28 ms |
29648 KB |
Output is correct |
16 |
Execution timed out |
4062 ms |
150008 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |