Submission #623517

# Submission time Handle Problem Language Result Execution time Memory
623517 2022-08-05T18:10:25 Z Lobo Game (APIO22_game) C++17
100 / 100
2399 ms 120900 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[maxm], B[maxm];
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);
    g[v].pb(cntedg);
    // gt[v].pb(cntedg);
    A[cntedg] = u;
    B[cntedg] = v;
    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 4 ms 7324 KB Output is correct
3 Correct 4 ms 7376 KB Output is correct
4 Correct 3 ms 7396 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7328 KB Output is correct
7 Correct 4 ms 7316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7248 KB Output is correct
2 Correct 4 ms 7324 KB Output is correct
3 Correct 4 ms 7376 KB Output is correct
4 Correct 3 ms 7396 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7328 KB Output is correct
7 Correct 4 ms 7316 KB Output is correct
8 Correct 4 ms 7376 KB Output is correct
9 Correct 4 ms 7248 KB Output is correct
10 Correct 4 ms 7376 KB Output is correct
11 Correct 4 ms 7376 KB Output is correct
12 Correct 5 ms 7376 KB Output is correct
13 Correct 4 ms 7376 KB Output is correct
14 Correct 4 ms 7376 KB Output is correct
15 Correct 4 ms 7316 KB Output is correct
16 Correct 4 ms 7376 KB Output is correct
17 Correct 4 ms 7376 KB Output is correct
18 Correct 4 ms 7376 KB Output is correct
19 Correct 5 ms 7376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7248 KB Output is correct
2 Correct 4 ms 7324 KB Output is correct
3 Correct 4 ms 7376 KB Output is correct
4 Correct 3 ms 7396 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7328 KB Output is correct
7 Correct 4 ms 7316 KB Output is correct
8 Correct 4 ms 7376 KB Output is correct
9 Correct 4 ms 7248 KB Output is correct
10 Correct 4 ms 7376 KB Output is correct
11 Correct 4 ms 7376 KB Output is correct
12 Correct 5 ms 7376 KB Output is correct
13 Correct 4 ms 7376 KB Output is correct
14 Correct 4 ms 7376 KB Output is correct
15 Correct 4 ms 7316 KB Output is correct
16 Correct 4 ms 7376 KB Output is correct
17 Correct 4 ms 7376 KB Output is correct
18 Correct 4 ms 7376 KB Output is correct
19 Correct 5 ms 7376 KB Output is correct
20 Correct 4 ms 7376 KB Output is correct
21 Correct 4 ms 7376 KB Output is correct
22 Correct 4 ms 7376 KB Output is correct
23 Correct 6 ms 7376 KB Output is correct
24 Correct 5 ms 7628 KB Output is correct
25 Correct 6 ms 7632 KB Output is correct
26 Correct 8 ms 7532 KB Output is correct
27 Correct 6 ms 7552 KB Output is correct
28 Correct 5 ms 7760 KB Output is correct
29 Correct 5 ms 7804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7248 KB Output is correct
2 Correct 4 ms 7324 KB Output is correct
3 Correct 4 ms 7376 KB Output is correct
4 Correct 3 ms 7396 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7328 KB Output is correct
7 Correct 4 ms 7316 KB Output is correct
8 Correct 4 ms 7376 KB Output is correct
9 Correct 4 ms 7248 KB Output is correct
10 Correct 4 ms 7376 KB Output is correct
11 Correct 4 ms 7376 KB Output is correct
12 Correct 5 ms 7376 KB Output is correct
13 Correct 4 ms 7376 KB Output is correct
14 Correct 4 ms 7376 KB Output is correct
15 Correct 4 ms 7316 KB Output is correct
16 Correct 4 ms 7376 KB Output is correct
17 Correct 4 ms 7376 KB Output is correct
18 Correct 4 ms 7376 KB Output is correct
19 Correct 5 ms 7376 KB Output is correct
20 Correct 4 ms 7376 KB Output is correct
21 Correct 4 ms 7376 KB Output is correct
22 Correct 4 ms 7376 KB Output is correct
23 Correct 6 ms 7376 KB Output is correct
24 Correct 5 ms 7628 KB Output is correct
25 Correct 6 ms 7632 KB Output is correct
26 Correct 8 ms 7532 KB Output is correct
27 Correct 6 ms 7552 KB Output is correct
28 Correct 5 ms 7760 KB Output is correct
29 Correct 5 ms 7804 KB Output is correct
30 Correct 18 ms 9156 KB Output is correct
31 Correct 8 ms 8316 KB Output is correct
32 Correct 31 ms 15364 KB Output is correct
33 Correct 25 ms 9444 KB Output is correct
34 Correct 69 ms 21148 KB Output is correct
35 Correct 58 ms 13568 KB Output is correct
36 Correct 46 ms 10096 KB Output is correct
37 Correct 48 ms 9652 KB Output is correct
38 Correct 38 ms 9712 KB Output is correct
39 Correct 46 ms 9868 KB Output is correct
40 Correct 83 ms 20500 KB Output is correct
41 Correct 49 ms 15944 KB Output is correct
42 Correct 38 ms 11700 KB Output is correct
43 Correct 55 ms 12728 KB Output is correct
44 Correct 64 ms 14224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7248 KB Output is correct
2 Correct 4 ms 7324 KB Output is correct
3 Correct 4 ms 7376 KB Output is correct
4 Correct 3 ms 7396 KB Output is correct
5 Correct 4 ms 7376 KB Output is correct
6 Correct 4 ms 7328 KB Output is correct
7 Correct 4 ms 7316 KB Output is correct
8 Correct 4 ms 7376 KB Output is correct
9 Correct 4 ms 7248 KB Output is correct
10 Correct 4 ms 7376 KB Output is correct
11 Correct 4 ms 7376 KB Output is correct
12 Correct 5 ms 7376 KB Output is correct
13 Correct 4 ms 7376 KB Output is correct
14 Correct 4 ms 7376 KB Output is correct
15 Correct 4 ms 7316 KB Output is correct
16 Correct 4 ms 7376 KB Output is correct
17 Correct 4 ms 7376 KB Output is correct
18 Correct 4 ms 7376 KB Output is correct
19 Correct 5 ms 7376 KB Output is correct
20 Correct 4 ms 7376 KB Output is correct
21 Correct 4 ms 7376 KB Output is correct
22 Correct 4 ms 7376 KB Output is correct
23 Correct 6 ms 7376 KB Output is correct
24 Correct 5 ms 7628 KB Output is correct
25 Correct 6 ms 7632 KB Output is correct
26 Correct 8 ms 7532 KB Output is correct
27 Correct 6 ms 7552 KB Output is correct
28 Correct 5 ms 7760 KB Output is correct
29 Correct 5 ms 7804 KB Output is correct
30 Correct 18 ms 9156 KB Output is correct
31 Correct 8 ms 8316 KB Output is correct
32 Correct 31 ms 15364 KB Output is correct
33 Correct 25 ms 9444 KB Output is correct
34 Correct 69 ms 21148 KB Output is correct
35 Correct 58 ms 13568 KB Output is correct
36 Correct 46 ms 10096 KB Output is correct
37 Correct 48 ms 9652 KB Output is correct
38 Correct 38 ms 9712 KB Output is correct
39 Correct 46 ms 9868 KB Output is correct
40 Correct 83 ms 20500 KB Output is correct
41 Correct 49 ms 15944 KB Output is correct
42 Correct 38 ms 11700 KB Output is correct
43 Correct 55 ms 12728 KB Output is correct
44 Correct 64 ms 14224 KB Output is correct
45 Correct 231 ms 23592 KB Output is correct
46 Correct 8 ms 8016 KB Output is correct
47 Correct 10 ms 7964 KB Output is correct
48 Correct 359 ms 53876 KB Output is correct
49 Correct 246 ms 27668 KB Output is correct
50 Correct 1140 ms 89272 KB Output is correct
51 Correct 1434 ms 61368 KB Output is correct
52 Correct 776 ms 29792 KB Output is correct
53 Correct 1129 ms 30616 KB Output is correct
54 Correct 1357 ms 31456 KB Output is correct
55 Correct 1692 ms 34844 KB Output is correct
56 Correct 1922 ms 31504 KB Output is correct
57 Correct 611 ms 29976 KB Output is correct
58 Correct 651 ms 30532 KB Output is correct
59 Correct 641 ms 30420 KB Output is correct
60 Correct 771 ms 30332 KB Output is correct
61 Correct 1105 ms 29972 KB Output is correct
62 Correct 614 ms 58104 KB Output is correct
63 Correct 547 ms 54348 KB Output is correct
64 Correct 1711 ms 120900 KB Output is correct
65 Correct 678 ms 43580 KB Output is correct
66 Correct 604 ms 39032 KB Output is correct
67 Correct 1202 ms 50120 KB Output is correct
68 Correct 170 ms 24136 KB Output is correct
69 Correct 53 ms 15416 KB Output is correct
70 Correct 1361 ms 57008 KB Output is correct
71 Correct 341 ms 28956 KB Output is correct
72 Correct 245 ms 24520 KB Output is correct
73 Correct 977 ms 64640 KB Output is correct
74 Correct 2399 ms 34116 KB Output is correct
75 Correct 1492 ms 60640 KB Output is correct
76 Correct 1982 ms 78896 KB Output is correct