# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
623514 |
2022-08-05T18:09:12 Z |
Lobo |
Game (APIO22_game) |
C++17 |
|
5 ms |
7376 KB |
#include "game.h"
#include<iostream>
#include<vector>
using namespace std;
#define pb push_back
#define fr first
#define sc second
#define mp make_pair
const int maxn = 3e5+10;
const int maxm = 5e5+10;
int n, k;
char dir[maxn][20];
// vector<pair<int,int>> g[maxn], gt[maxn];
vector<int> g[maxn];
int ans = 0;
char lvedg[maxm];
int ledg[maxm], redg[maxm], A[maxn], B[maxn];
int cntedg = 0;
/*
0 -> fora desse nível
1 -> chega em mid
2 -> mid chega em
*/
void recall(int a);
void att(int l, int r, int lv, int a, int b, int id);
void recall(int a) {
for(auto id : g[a]) {
att(ledg[id],redg[id],lvedg[id],A[id],B[id],id);
// att(0,k-1,0,a,b,id);
}
// for(auto B : gt[a]) {
// int b = B.fr;
// int id = B.sc;
// att(ledg[id],redg[id],lvedg[id],b,a,id);
// // att(0,k-1,0,b,a,id);
// }
}
void att(int l, int r, int lv, int a, int b, int id) {
lvedg[id] = lv;
ledg[id] = l;
redg[id] = r;
if(l > r) return;
int mid = (l+r)/2;
if(a == mid) {
if(dir[b][lv] == 0) {
dir[b][lv] = 2; //mid chega no b
recall(b); //b muda
}
else if(dir[b][lv] == 1) {
ans = 1; // b chega em mid e mid chega em b
}
return;
}
if(b == mid) {
if(dir[a][lv] == 0) {
dir[a][lv] = 1; //a chega em mid
recall(a); //a muda
}
else if(dir[a][lv] == 2) {
ans = 1; // mid chega em a e a chega em mid
}
return;
}
if(dir[a][lv] == 0 && dir[b][lv] == 1) {
//b chega em mid, a chega em b -> a chega em mid
dir[a][lv] = 1;
recall(a); //a mudou
att(l,mid-1,lv+1,a,b,id); //os dois tão no L
return;
}
if(dir[a][lv] == 2 && dir[b][lv] == 0) {
//mid chega em a, a chega em b -> mid chega em b
dir[b][lv] = 2;
recall(b); //b mudou
att(mid+1,r,lv+1,a,b,id); //os dois tão no R
return;
}
if(dir[a][lv] == 2 && dir[b][lv] == 1) {
//mid chega em a, a chega em b, b chega em mid -> mid chega em mid
ans = 1;
return;
}
if(dir[a][lv] == 1 && dir[b][lv] == 1) {
att(l,mid-1,lv+1,a,b,id); //os dois tão no L | BRUTE ASSIM FICA LOG²
return;
}
if(dir[a][lv] == 2 && dir[b][lv] == 2) {
att(mid+1,r,lv+1,a,b,id); //os dois tão no R | BRUTE ASSIM FICA LOG²
return;
}
}
void build(int l, int r, int lv) {
if(l > r) return;
int mid = (l+r)/2;
for(int i = l; i < mid; i++) {
dir[i][lv] = 1;
}
for(int i = mid+1; i <= r; i++) {
dir[i][lv] = 2;
}
build(l,mid-1,lv+1);
build(mid+1,r,lv+1);
}
void init(int N, int K) {
n = N;
k = K;
build(0,k-1,0);
}
int add_teleporter(int u, int v) {
g[u].pb(cntedg);
// gt[v].pb(cntedg);
if(u == v && u < k) return 1;
att(0,k-1,0,u,v,cntedg);
cntedg++;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7248 KB |
Output is correct |
2 |
Correct |
3 ms |
7248 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
4 ms |
7376 KB |
Output is correct |
5 |
Correct |
4 ms |
7376 KB |
Output is correct |
6 |
Correct |
4 ms |
7376 KB |
Output is correct |
7 |
Correct |
4 ms |
7376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7248 KB |
Output is correct |
2 |
Correct |
3 ms |
7248 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
4 ms |
7376 KB |
Output is correct |
5 |
Correct |
4 ms |
7376 KB |
Output is correct |
6 |
Correct |
4 ms |
7376 KB |
Output is correct |
7 |
Correct |
4 ms |
7376 KB |
Output is correct |
8 |
Correct |
3 ms |
7376 KB |
Output is correct |
9 |
Correct |
5 ms |
7248 KB |
Output is correct |
10 |
Correct |
3 ms |
7376 KB |
Output is correct |
11 |
Incorrect |
4 ms |
7376 KB |
Wrong Answer[1] |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7248 KB |
Output is correct |
2 |
Correct |
3 ms |
7248 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
4 ms |
7376 KB |
Output is correct |
5 |
Correct |
4 ms |
7376 KB |
Output is correct |
6 |
Correct |
4 ms |
7376 KB |
Output is correct |
7 |
Correct |
4 ms |
7376 KB |
Output is correct |
8 |
Correct |
3 ms |
7376 KB |
Output is correct |
9 |
Correct |
5 ms |
7248 KB |
Output is correct |
10 |
Correct |
3 ms |
7376 KB |
Output is correct |
11 |
Incorrect |
4 ms |
7376 KB |
Wrong Answer[1] |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7248 KB |
Output is correct |
2 |
Correct |
3 ms |
7248 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
4 ms |
7376 KB |
Output is correct |
5 |
Correct |
4 ms |
7376 KB |
Output is correct |
6 |
Correct |
4 ms |
7376 KB |
Output is correct |
7 |
Correct |
4 ms |
7376 KB |
Output is correct |
8 |
Correct |
3 ms |
7376 KB |
Output is correct |
9 |
Correct |
5 ms |
7248 KB |
Output is correct |
10 |
Correct |
3 ms |
7376 KB |
Output is correct |
11 |
Incorrect |
4 ms |
7376 KB |
Wrong Answer[1] |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7248 KB |
Output is correct |
2 |
Correct |
3 ms |
7248 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
4 ms |
7376 KB |
Output is correct |
5 |
Correct |
4 ms |
7376 KB |
Output is correct |
6 |
Correct |
4 ms |
7376 KB |
Output is correct |
7 |
Correct |
4 ms |
7376 KB |
Output is correct |
8 |
Correct |
3 ms |
7376 KB |
Output is correct |
9 |
Correct |
5 ms |
7248 KB |
Output is correct |
10 |
Correct |
3 ms |
7376 KB |
Output is correct |
11 |
Incorrect |
4 ms |
7376 KB |
Wrong Answer[1] |
12 |
Halted |
0 ms |
0 KB |
- |