# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
771051 |
2023-07-02T11:45:23 Z |
khshg |
Werewolf (IOI18_werewolf) |
C++14 |
|
4000 ms |
40716 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(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(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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4027 ms |
40716 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |