# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1037878 |
2024-07-29T09:35:36 Z |
_8_8_ |
Game (APIO22_game) |
C++17 |
|
21 ms |
127252 KB |
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 12;
vector<int> g[N],gr[N];
set<int> L[N * 4],R[N * 4];
int k;
void build(int v = 1,int tl = 0,int tr = k - 1) {
int tm = (tl + tr) >> 1;
for(int i = tl;i <= tr;i++) {
if(i <= tm) {
L[v].insert(i);
}
if(i >= tm) {
R[v].insert(i);
}
}
if(tl == tr) return;
build(v + v,tl,tm);
build(v + v + 1,tm + 1,tr);
}
void init(int n, int K) {
k = K;
for(int i = 0;i <= k - 2;i++) {
g[i].push_back(i + 1);
gr[i + 1].push_back(i);
}
build();
}
bool CYC = false;
void add(int x,int y,int v = 1,int tl = 0,int tr = k - 1) {
int tm = (tl + tr) >> 1;
function<void(int)> dfs = [&](int u){
// cout << tm << ' ' << u << "R\n";
R[v].insert(u);
if(L[v].find(u) != L[v].end()) {
CYC = 1;
return;
}
for(int to:g[u]) {
if(R[v].find(to) == R[v].end()) {
dfs(to);
}
if(CYC) return;
}
if(CYC) return;
};
function<void(int)> dfs1 = [&](int u){
// cout << tm << ' ' << u << "L\n";
if(R[v].find(u) != R[v].end()) {
CYC = 1;
return;
}
L[v].insert(u);
for(int to:gr[u]) {
if(L[v].find(to) == L[v].end()) {
dfs1(to);
}
if(CYC) return;
}
if(CYC) return;
};
// cout << tm << ' ' << x << ' ' << y << "A\n";
if(R[v].find(x) != R[v].end() && R[v].find(y) == R[v].end()) {
dfs(y);
if(CYC) return;
if(tl != tr) {
add(x,y,v+v+1,tm+1,tr);
}
}
if(L[v].find(y) != L[v].end() && L[v].find(x) == L[v].end()) {
dfs1(x);
if(CYC) return;
if(tl != tr) {
add(x,y,v+v,tl,tm);
}
}
}
int add_teleporter(int u, int v) {
if(CYC) return 1;
if(max(u,v) <= k - 1) {
if(u >= v) {
CYC = 1;
return 1;
}
return 0;
}
// cout << u << ' ' << v << '\n';
g[u].push_back(v);
gr[v].push_back(u);
add(u,v);
return CYC;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
127064 KB |
Output is correct |
2 |
Correct |
21 ms |
127252 KB |
Output is correct |
3 |
Correct |
21 ms |
127064 KB |
Output is correct |
4 |
Correct |
21 ms |
127168 KB |
Output is correct |
5 |
Correct |
20 ms |
127064 KB |
Output is correct |
6 |
Correct |
20 ms |
127064 KB |
Output is correct |
7 |
Correct |
20 ms |
127064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
127064 KB |
Output is correct |
2 |
Correct |
21 ms |
127252 KB |
Output is correct |
3 |
Correct |
21 ms |
127064 KB |
Output is correct |
4 |
Correct |
21 ms |
127168 KB |
Output is correct |
5 |
Correct |
20 ms |
127064 KB |
Output is correct |
6 |
Correct |
20 ms |
127064 KB |
Output is correct |
7 |
Correct |
20 ms |
127064 KB |
Output is correct |
8 |
Correct |
20 ms |
127064 KB |
Output is correct |
9 |
Correct |
21 ms |
127216 KB |
Output is correct |
10 |
Correct |
20 ms |
127064 KB |
Output is correct |
11 |
Correct |
20 ms |
127064 KB |
Output is correct |
12 |
Correct |
20 ms |
127064 KB |
Output is correct |
13 |
Incorrect |
20 ms |
127064 KB |
Wrong Answer[1] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
127064 KB |
Output is correct |
2 |
Correct |
21 ms |
127252 KB |
Output is correct |
3 |
Correct |
21 ms |
127064 KB |
Output is correct |
4 |
Correct |
21 ms |
127168 KB |
Output is correct |
5 |
Correct |
20 ms |
127064 KB |
Output is correct |
6 |
Correct |
20 ms |
127064 KB |
Output is correct |
7 |
Correct |
20 ms |
127064 KB |
Output is correct |
8 |
Correct |
20 ms |
127064 KB |
Output is correct |
9 |
Correct |
21 ms |
127216 KB |
Output is correct |
10 |
Correct |
20 ms |
127064 KB |
Output is correct |
11 |
Correct |
20 ms |
127064 KB |
Output is correct |
12 |
Correct |
20 ms |
127064 KB |
Output is correct |
13 |
Incorrect |
20 ms |
127064 KB |
Wrong Answer[1] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
127064 KB |
Output is correct |
2 |
Correct |
21 ms |
127252 KB |
Output is correct |
3 |
Correct |
21 ms |
127064 KB |
Output is correct |
4 |
Correct |
21 ms |
127168 KB |
Output is correct |
5 |
Correct |
20 ms |
127064 KB |
Output is correct |
6 |
Correct |
20 ms |
127064 KB |
Output is correct |
7 |
Correct |
20 ms |
127064 KB |
Output is correct |
8 |
Correct |
20 ms |
127064 KB |
Output is correct |
9 |
Correct |
21 ms |
127216 KB |
Output is correct |
10 |
Correct |
20 ms |
127064 KB |
Output is correct |
11 |
Correct |
20 ms |
127064 KB |
Output is correct |
12 |
Correct |
20 ms |
127064 KB |
Output is correct |
13 |
Incorrect |
20 ms |
127064 KB |
Wrong Answer[1] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
127064 KB |
Output is correct |
2 |
Correct |
21 ms |
127252 KB |
Output is correct |
3 |
Correct |
21 ms |
127064 KB |
Output is correct |
4 |
Correct |
21 ms |
127168 KB |
Output is correct |
5 |
Correct |
20 ms |
127064 KB |
Output is correct |
6 |
Correct |
20 ms |
127064 KB |
Output is correct |
7 |
Correct |
20 ms |
127064 KB |
Output is correct |
8 |
Correct |
20 ms |
127064 KB |
Output is correct |
9 |
Correct |
21 ms |
127216 KB |
Output is correct |
10 |
Correct |
20 ms |
127064 KB |
Output is correct |
11 |
Correct |
20 ms |
127064 KB |
Output is correct |
12 |
Correct |
20 ms |
127064 KB |
Output is correct |
13 |
Incorrect |
20 ms |
127064 KB |
Wrong Answer[1] |
14 |
Halted |
0 ms |
0 KB |
- |