# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1038414 |
2024-07-29T19:04:28 Z |
_8_8_ |
게임 (APIO22_game) |
C++17 |
|
42 ms |
113720 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 * 3],R[N * 3];
int k;
int nn;
void build(int v = 1,int tl = 0,int tr = k - 1) {
if(tl > tr) return;
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 - 1);
build(v + v + 1,tm + 1,tr);
}
void init(int n, int K) {
k = K;
nn = n;
for(int i = 0;i <= k - 2;i++) {
g[i].push_back(i + 1);
gr[i + 1].push_back(i);
}
build();
}
bool CYC = false;
vector<int>_r[N];
bool check(int tm,int prev,int v,int val) {
if(prev == -1) return 1;
if(prev < tm && R[v / 2].find(val) == R[v / 2].end()) return false;
if(prev > tm && L[v / 2].find(val) == L[v / 2].end()) return false;
return 1;
}
void add(int x,int y,int v = 1,int tl = 0,int tr = k - 1,int prev = -1) {
if(tl > tr) return;
if(CYC) return;
int tm = (tl + tr) >> 1;
bool ok = false,ok1 = false;
function<void(int)> dfs = [&](int u){
R[v].insert(u);
_r[u].push_back(tm);
ok = 1;
if(L[v].find(u) != L[v].end()) {
CYC = 1;
return;
}
for(int to:g[u]) {
if(R[v].find(to) == R[v].end() && check(tm,prev,v,to)) {
dfs(to);
}
if(CYC) return;
}
if(CYC) return;
};
if(R[v].find(x) != R[v].end()) {
if(L[v].find(y) != L[v].end()) {
CYC = 1;
return;
}
if(check(tm,prev,v,y) && R[v].find(y) == R[v].end()) dfs(y);
if(tl != tr) add(x,y,v + v + 1,tm + 1,tr,tm);
} else {
if(tl != tr) add(x,y,v + v,tl,tm - 1,tm);
}
}
void addl(int x,int y,int v = 1,int tl = 0,int tr = k - 1,int prev = -1) {
if(tl > tr) return;
if(CYC) return;
int tm = (tl + tr) >> 1;
function<void(int)> dfs1 = [&](int u){
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() && (1 || check(tm,prev,v,to))) {
dfs1(to);
}
if(CYC) return;
}
if(CYC) return;
};
if(L[v].find(y) != L[v].end()) {
if(R[v].find(x) != R[v].end()) {
CYC = 1;
return;
}
if(L[v].find(x) == L[v].end() && (1||check(tm,prev,v,x))) dfs1(x);
if(tl != tr) addl(x,y,v + v,tl,tm -1,tm);
} else {
if(tl != tr) addl(x,y,v+v+1,tm+1,tr,tm);
}
}
int add_teleporter(int u, int v) {
if(max(u,v) <= k - 1) {
if(u >= v) {
CYC = 1;
return 1;
}
return 0;
}
if(CYC) return 1;
g[u].push_back(v);
gr[v].push_back(u);
add(u,v);
addl(u,v);
return CYC;
}
Compilation message
game.cpp: In function 'void add(int, int, int, int, int, int)':
game.cpp:47:21: warning: unused variable 'ok1' [-Wunused-variable]
47 | bool ok = false,ok1 = false;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
106072 KB |
Output is correct |
2 |
Correct |
17 ms |
106072 KB |
Output is correct |
3 |
Correct |
16 ms |
106072 KB |
Output is correct |
4 |
Correct |
17 ms |
106072 KB |
Output is correct |
5 |
Correct |
16 ms |
106072 KB |
Output is correct |
6 |
Correct |
16 ms |
106072 KB |
Output is correct |
7 |
Correct |
16 ms |
106072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
106072 KB |
Output is correct |
2 |
Correct |
17 ms |
106072 KB |
Output is correct |
3 |
Correct |
16 ms |
106072 KB |
Output is correct |
4 |
Correct |
17 ms |
106072 KB |
Output is correct |
5 |
Correct |
16 ms |
106072 KB |
Output is correct |
6 |
Correct |
16 ms |
106072 KB |
Output is correct |
7 |
Correct |
16 ms |
106072 KB |
Output is correct |
8 |
Correct |
17 ms |
106072 KB |
Output is correct |
9 |
Correct |
16 ms |
106072 KB |
Output is correct |
10 |
Correct |
17 ms |
106072 KB |
Output is correct |
11 |
Correct |
16 ms |
105880 KB |
Output is correct |
12 |
Correct |
17 ms |
106072 KB |
Output is correct |
13 |
Correct |
17 ms |
106072 KB |
Output is correct |
14 |
Correct |
17 ms |
106128 KB |
Output is correct |
15 |
Correct |
17 ms |
106072 KB |
Output is correct |
16 |
Correct |
19 ms |
106072 KB |
Output is correct |
17 |
Correct |
21 ms |
106072 KB |
Output is correct |
18 |
Correct |
17 ms |
106072 KB |
Output is correct |
19 |
Correct |
17 ms |
105900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
106072 KB |
Output is correct |
2 |
Correct |
17 ms |
106072 KB |
Output is correct |
3 |
Correct |
16 ms |
106072 KB |
Output is correct |
4 |
Correct |
17 ms |
106072 KB |
Output is correct |
5 |
Correct |
16 ms |
106072 KB |
Output is correct |
6 |
Correct |
16 ms |
106072 KB |
Output is correct |
7 |
Correct |
16 ms |
106072 KB |
Output is correct |
8 |
Correct |
17 ms |
106072 KB |
Output is correct |
9 |
Correct |
16 ms |
106072 KB |
Output is correct |
10 |
Correct |
17 ms |
106072 KB |
Output is correct |
11 |
Correct |
16 ms |
105880 KB |
Output is correct |
12 |
Correct |
17 ms |
106072 KB |
Output is correct |
13 |
Correct |
17 ms |
106072 KB |
Output is correct |
14 |
Correct |
17 ms |
106128 KB |
Output is correct |
15 |
Correct |
17 ms |
106072 KB |
Output is correct |
16 |
Correct |
19 ms |
106072 KB |
Output is correct |
17 |
Correct |
21 ms |
106072 KB |
Output is correct |
18 |
Correct |
17 ms |
106072 KB |
Output is correct |
19 |
Correct |
17 ms |
105900 KB |
Output is correct |
20 |
Correct |
17 ms |
106072 KB |
Output is correct |
21 |
Correct |
18 ms |
106072 KB |
Output is correct |
22 |
Correct |
19 ms |
106328 KB |
Output is correct |
23 |
Correct |
17 ms |
106148 KB |
Output is correct |
24 |
Correct |
40 ms |
113720 KB |
Output is correct |
25 |
Correct |
42 ms |
110160 KB |
Output is correct |
26 |
Correct |
27 ms |
106576 KB |
Output is correct |
27 |
Correct |
30 ms |
107600 KB |
Output is correct |
28 |
Incorrect |
22 ms |
106584 KB |
Wrong Answer[1] |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
106072 KB |
Output is correct |
2 |
Correct |
17 ms |
106072 KB |
Output is correct |
3 |
Correct |
16 ms |
106072 KB |
Output is correct |
4 |
Correct |
17 ms |
106072 KB |
Output is correct |
5 |
Correct |
16 ms |
106072 KB |
Output is correct |
6 |
Correct |
16 ms |
106072 KB |
Output is correct |
7 |
Correct |
16 ms |
106072 KB |
Output is correct |
8 |
Correct |
17 ms |
106072 KB |
Output is correct |
9 |
Correct |
16 ms |
106072 KB |
Output is correct |
10 |
Correct |
17 ms |
106072 KB |
Output is correct |
11 |
Correct |
16 ms |
105880 KB |
Output is correct |
12 |
Correct |
17 ms |
106072 KB |
Output is correct |
13 |
Correct |
17 ms |
106072 KB |
Output is correct |
14 |
Correct |
17 ms |
106128 KB |
Output is correct |
15 |
Correct |
17 ms |
106072 KB |
Output is correct |
16 |
Correct |
19 ms |
106072 KB |
Output is correct |
17 |
Correct |
21 ms |
106072 KB |
Output is correct |
18 |
Correct |
17 ms |
106072 KB |
Output is correct |
19 |
Correct |
17 ms |
105900 KB |
Output is correct |
20 |
Correct |
17 ms |
106072 KB |
Output is correct |
21 |
Correct |
18 ms |
106072 KB |
Output is correct |
22 |
Correct |
19 ms |
106328 KB |
Output is correct |
23 |
Correct |
17 ms |
106148 KB |
Output is correct |
24 |
Correct |
40 ms |
113720 KB |
Output is correct |
25 |
Correct |
42 ms |
110160 KB |
Output is correct |
26 |
Correct |
27 ms |
106576 KB |
Output is correct |
27 |
Correct |
30 ms |
107600 KB |
Output is correct |
28 |
Incorrect |
22 ms |
106584 KB |
Wrong Answer[1] |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
106072 KB |
Output is correct |
2 |
Correct |
17 ms |
106072 KB |
Output is correct |
3 |
Correct |
16 ms |
106072 KB |
Output is correct |
4 |
Correct |
17 ms |
106072 KB |
Output is correct |
5 |
Correct |
16 ms |
106072 KB |
Output is correct |
6 |
Correct |
16 ms |
106072 KB |
Output is correct |
7 |
Correct |
16 ms |
106072 KB |
Output is correct |
8 |
Correct |
17 ms |
106072 KB |
Output is correct |
9 |
Correct |
16 ms |
106072 KB |
Output is correct |
10 |
Correct |
17 ms |
106072 KB |
Output is correct |
11 |
Correct |
16 ms |
105880 KB |
Output is correct |
12 |
Correct |
17 ms |
106072 KB |
Output is correct |
13 |
Correct |
17 ms |
106072 KB |
Output is correct |
14 |
Correct |
17 ms |
106128 KB |
Output is correct |
15 |
Correct |
17 ms |
106072 KB |
Output is correct |
16 |
Correct |
19 ms |
106072 KB |
Output is correct |
17 |
Correct |
21 ms |
106072 KB |
Output is correct |
18 |
Correct |
17 ms |
106072 KB |
Output is correct |
19 |
Correct |
17 ms |
105900 KB |
Output is correct |
20 |
Correct |
17 ms |
106072 KB |
Output is correct |
21 |
Correct |
18 ms |
106072 KB |
Output is correct |
22 |
Correct |
19 ms |
106328 KB |
Output is correct |
23 |
Correct |
17 ms |
106148 KB |
Output is correct |
24 |
Correct |
40 ms |
113720 KB |
Output is correct |
25 |
Correct |
42 ms |
110160 KB |
Output is correct |
26 |
Correct |
27 ms |
106576 KB |
Output is correct |
27 |
Correct |
30 ms |
107600 KB |
Output is correct |
28 |
Incorrect |
22 ms |
106584 KB |
Wrong Answer[1] |
29 |
Halted |
0 ms |
0 KB |
- |