Submission #623320

# Submission time Handle Problem Language Result Execution time Memory
623320 2022-08-05T12:49:07 Z Lobo Game (APIO22_game) C++17
100 / 100
3031 ms 239828 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, dir[maxn][19];
vector<pair<int,int>> g[maxn], gt[maxn];
int ans = 0;
// int lvedg[maxm], ledg[maxm], redg[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 B : g[a]) {
        int b = B.fr;
        int id = B.sc;
        // att(ledg[id],redg[id],lvedg[id],a,b,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(mp(v,cntedg));
    gt[v].pb(mp(u,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 7 ms 14288 KB Output is correct
2 Correct 7 ms 14288 KB Output is correct
3 Correct 8 ms 14360 KB Output is correct
4 Correct 9 ms 14288 KB Output is correct
5 Correct 8 ms 14288 KB Output is correct
6 Correct 10 ms 14332 KB Output is correct
7 Correct 7 ms 14412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14288 KB Output is correct
2 Correct 7 ms 14288 KB Output is correct
3 Correct 8 ms 14360 KB Output is correct
4 Correct 9 ms 14288 KB Output is correct
5 Correct 8 ms 14288 KB Output is correct
6 Correct 10 ms 14332 KB Output is correct
7 Correct 7 ms 14412 KB Output is correct
8 Correct 7 ms 14288 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 8 ms 14288 KB Output is correct
11 Correct 7 ms 14288 KB Output is correct
12 Correct 8 ms 14412 KB Output is correct
13 Correct 7 ms 14288 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 9 ms 14288 KB Output is correct
16 Correct 8 ms 14536 KB Output is correct
17 Correct 8 ms 14416 KB Output is correct
18 Correct 8 ms 14392 KB Output is correct
19 Correct 10 ms 14376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14288 KB Output is correct
2 Correct 7 ms 14288 KB Output is correct
3 Correct 8 ms 14360 KB Output is correct
4 Correct 9 ms 14288 KB Output is correct
5 Correct 8 ms 14288 KB Output is correct
6 Correct 10 ms 14332 KB Output is correct
7 Correct 7 ms 14412 KB Output is correct
8 Correct 7 ms 14288 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 8 ms 14288 KB Output is correct
11 Correct 7 ms 14288 KB Output is correct
12 Correct 8 ms 14412 KB Output is correct
13 Correct 7 ms 14288 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 9 ms 14288 KB Output is correct
16 Correct 8 ms 14536 KB Output is correct
17 Correct 8 ms 14416 KB Output is correct
18 Correct 8 ms 14392 KB Output is correct
19 Correct 10 ms 14376 KB Output is correct
20 Correct 9 ms 14416 KB Output is correct
21 Correct 8 ms 14456 KB Output is correct
22 Correct 10 ms 14696 KB Output is correct
23 Correct 13 ms 14416 KB Output is correct
24 Correct 10 ms 14672 KB Output is correct
25 Correct 11 ms 14600 KB Output is correct
26 Correct 14 ms 14604 KB Output is correct
27 Correct 12 ms 14544 KB Output is correct
28 Correct 10 ms 14800 KB Output is correct
29 Correct 11 ms 14800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14288 KB Output is correct
2 Correct 7 ms 14288 KB Output is correct
3 Correct 8 ms 14360 KB Output is correct
4 Correct 9 ms 14288 KB Output is correct
5 Correct 8 ms 14288 KB Output is correct
6 Correct 10 ms 14332 KB Output is correct
7 Correct 7 ms 14412 KB Output is correct
8 Correct 7 ms 14288 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 8 ms 14288 KB Output is correct
11 Correct 7 ms 14288 KB Output is correct
12 Correct 8 ms 14412 KB Output is correct
13 Correct 7 ms 14288 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 9 ms 14288 KB Output is correct
16 Correct 8 ms 14536 KB Output is correct
17 Correct 8 ms 14416 KB Output is correct
18 Correct 8 ms 14392 KB Output is correct
19 Correct 10 ms 14376 KB Output is correct
20 Correct 9 ms 14416 KB Output is correct
21 Correct 8 ms 14456 KB Output is correct
22 Correct 10 ms 14696 KB Output is correct
23 Correct 13 ms 14416 KB Output is correct
24 Correct 10 ms 14672 KB Output is correct
25 Correct 11 ms 14600 KB Output is correct
26 Correct 14 ms 14604 KB Output is correct
27 Correct 12 ms 14544 KB Output is correct
28 Correct 10 ms 14800 KB Output is correct
29 Correct 11 ms 14800 KB Output is correct
30 Correct 32 ms 17512 KB Output is correct
31 Correct 13 ms 15616 KB Output is correct
32 Correct 56 ms 32312 KB Output is correct
33 Correct 32 ms 18616 KB Output is correct
34 Correct 108 ms 45640 KB Output is correct
35 Correct 101 ms 21676 KB Output is correct
36 Correct 65 ms 18740 KB Output is correct
37 Correct 71 ms 18516 KB Output is correct
38 Correct 45 ms 18420 KB Output is correct
39 Correct 53 ms 18424 KB Output is correct
40 Correct 85 ms 51504 KB Output is correct
41 Correct 100 ms 23280 KB Output is correct
42 Correct 86 ms 23772 KB Output is correct
43 Correct 88 ms 20936 KB Output is correct
44 Correct 88 ms 26136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14288 KB Output is correct
2 Correct 7 ms 14288 KB Output is correct
3 Correct 8 ms 14360 KB Output is correct
4 Correct 9 ms 14288 KB Output is correct
5 Correct 8 ms 14288 KB Output is correct
6 Correct 10 ms 14332 KB Output is correct
7 Correct 7 ms 14412 KB Output is correct
8 Correct 7 ms 14288 KB Output is correct
9 Correct 8 ms 14288 KB Output is correct
10 Correct 8 ms 14288 KB Output is correct
11 Correct 7 ms 14288 KB Output is correct
12 Correct 8 ms 14412 KB Output is correct
13 Correct 7 ms 14288 KB Output is correct
14 Correct 8 ms 14416 KB Output is correct
15 Correct 9 ms 14288 KB Output is correct
16 Correct 8 ms 14536 KB Output is correct
17 Correct 8 ms 14416 KB Output is correct
18 Correct 8 ms 14392 KB Output is correct
19 Correct 10 ms 14376 KB Output is correct
20 Correct 9 ms 14416 KB Output is correct
21 Correct 8 ms 14456 KB Output is correct
22 Correct 10 ms 14696 KB Output is correct
23 Correct 13 ms 14416 KB Output is correct
24 Correct 10 ms 14672 KB Output is correct
25 Correct 11 ms 14600 KB Output is correct
26 Correct 14 ms 14604 KB Output is correct
27 Correct 12 ms 14544 KB Output is correct
28 Correct 10 ms 14800 KB Output is correct
29 Correct 11 ms 14800 KB Output is correct
30 Correct 32 ms 17512 KB Output is correct
31 Correct 13 ms 15616 KB Output is correct
32 Correct 56 ms 32312 KB Output is correct
33 Correct 32 ms 18616 KB Output is correct
34 Correct 108 ms 45640 KB Output is correct
35 Correct 101 ms 21676 KB Output is correct
36 Correct 65 ms 18740 KB Output is correct
37 Correct 71 ms 18516 KB Output is correct
38 Correct 45 ms 18420 KB Output is correct
39 Correct 53 ms 18424 KB Output is correct
40 Correct 85 ms 51504 KB Output is correct
41 Correct 100 ms 23280 KB Output is correct
42 Correct 86 ms 23772 KB Output is correct
43 Correct 88 ms 20936 KB Output is correct
44 Correct 88 ms 26136 KB Output is correct
45 Correct 302 ms 31036 KB Output is correct
46 Correct 15 ms 14928 KB Output is correct
47 Correct 15 ms 15112 KB Output is correct
48 Correct 414 ms 75560 KB Output is correct
49 Correct 301 ms 53352 KB Output is correct
50 Correct 1430 ms 239828 KB Output is correct
51 Correct 1743 ms 103144 KB Output is correct
52 Correct 821 ms 56152 KB Output is correct
53 Correct 1301 ms 56580 KB Output is correct
54 Correct 1645 ms 57036 KB Output is correct
55 Correct 1985 ms 59012 KB Output is correct
56 Correct 2413 ms 57280 KB Output is correct
57 Correct 752 ms 51940 KB Output is correct
58 Correct 751 ms 52308 KB Output is correct
59 Correct 754 ms 52200 KB Output is correct
60 Correct 884 ms 52396 KB Output is correct
61 Correct 1357 ms 51444 KB Output is correct
62 Correct 934 ms 74312 KB Output is correct
63 Correct 793 ms 82212 KB Output is correct
64 Correct 2162 ms 160340 KB Output is correct
65 Correct 888 ms 64132 KB Output is correct
66 Correct 875 ms 59648 KB Output is correct
67 Correct 1445 ms 115416 KB Output is correct
68 Correct 226 ms 44968 KB Output is correct
69 Correct 65 ms 25668 KB Output is correct
70 Correct 1590 ms 105380 KB Output is correct
71 Correct 387 ms 51136 KB Output is correct
72 Correct 352 ms 46800 KB Output is correct
73 Correct 1247 ms 80712 KB Output is correct
74 Correct 3031 ms 58044 KB Output is correct
75 Correct 1763 ms 79180 KB Output is correct
76 Correct 2096 ms 94468 KB Output is correct