답안 #623313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
623313 2022-08-05T12:43:26 Z Lobo 게임 (APIO22_game) C++17
60 / 100
448 ms 262144 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][20];
vector<pair<int,int>> g[maxn], gt[maxn];
int ans = 0;
int lvedg[maxm], ledg[maxm], redg[maxm], 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);
    }
    for(auto B : gt[a]) {
        int b = B.fr;
        int id = B.sc;
        att(ledg[id],redg[id],lvedg[id],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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14304 KB Output is correct
2 Correct 8 ms 14364 KB Output is correct
3 Correct 8 ms 14328 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14440 KB Output is correct
6 Correct 8 ms 14416 KB Output is correct
7 Correct 10 ms 14440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14304 KB Output is correct
2 Correct 8 ms 14364 KB Output is correct
3 Correct 8 ms 14328 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14440 KB Output is correct
6 Correct 8 ms 14416 KB Output is correct
7 Correct 10 ms 14440 KB Output is correct
8 Correct 7 ms 14416 KB Output is correct
9 Correct 7 ms 14288 KB Output is correct
10 Correct 7 ms 14416 KB Output is correct
11 Correct 8 ms 14416 KB Output is correct
12 Correct 9 ms 14416 KB Output is correct
13 Correct 8 ms 14416 KB Output is correct
14 Correct 8 ms 14428 KB Output is correct
15 Correct 7 ms 14416 KB Output is correct
16 Correct 9 ms 14416 KB Output is correct
17 Correct 9 ms 14524 KB Output is correct
18 Correct 8 ms 14416 KB Output is correct
19 Correct 8 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14304 KB Output is correct
2 Correct 8 ms 14364 KB Output is correct
3 Correct 8 ms 14328 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14440 KB Output is correct
6 Correct 8 ms 14416 KB Output is correct
7 Correct 10 ms 14440 KB Output is correct
8 Correct 7 ms 14416 KB Output is correct
9 Correct 7 ms 14288 KB Output is correct
10 Correct 7 ms 14416 KB Output is correct
11 Correct 8 ms 14416 KB Output is correct
12 Correct 9 ms 14416 KB Output is correct
13 Correct 8 ms 14416 KB Output is correct
14 Correct 8 ms 14428 KB Output is correct
15 Correct 7 ms 14416 KB Output is correct
16 Correct 9 ms 14416 KB Output is correct
17 Correct 9 ms 14524 KB Output is correct
18 Correct 8 ms 14416 KB Output is correct
19 Correct 8 ms 14416 KB Output is correct
20 Correct 9 ms 14544 KB Output is correct
21 Correct 7 ms 14416 KB Output is correct
22 Correct 9 ms 14816 KB Output is correct
23 Correct 8 ms 14544 KB Output is correct
24 Correct 9 ms 14672 KB Output is correct
25 Correct 12 ms 14752 KB Output is correct
26 Correct 11 ms 14580 KB Output is correct
27 Correct 11 ms 14636 KB Output is correct
28 Correct 10 ms 14932 KB Output is correct
29 Correct 10 ms 14928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14304 KB Output is correct
2 Correct 8 ms 14364 KB Output is correct
3 Correct 8 ms 14328 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14440 KB Output is correct
6 Correct 8 ms 14416 KB Output is correct
7 Correct 10 ms 14440 KB Output is correct
8 Correct 7 ms 14416 KB Output is correct
9 Correct 7 ms 14288 KB Output is correct
10 Correct 7 ms 14416 KB Output is correct
11 Correct 8 ms 14416 KB Output is correct
12 Correct 9 ms 14416 KB Output is correct
13 Correct 8 ms 14416 KB Output is correct
14 Correct 8 ms 14428 KB Output is correct
15 Correct 7 ms 14416 KB Output is correct
16 Correct 9 ms 14416 KB Output is correct
17 Correct 9 ms 14524 KB Output is correct
18 Correct 8 ms 14416 KB Output is correct
19 Correct 8 ms 14416 KB Output is correct
20 Correct 9 ms 14544 KB Output is correct
21 Correct 7 ms 14416 KB Output is correct
22 Correct 9 ms 14816 KB Output is correct
23 Correct 8 ms 14544 KB Output is correct
24 Correct 9 ms 14672 KB Output is correct
25 Correct 12 ms 14752 KB Output is correct
26 Correct 11 ms 14580 KB Output is correct
27 Correct 11 ms 14636 KB Output is correct
28 Correct 10 ms 14932 KB Output is correct
29 Correct 10 ms 14928 KB Output is correct
30 Correct 29 ms 18056 KB Output is correct
31 Correct 12 ms 15696 KB Output is correct
32 Correct 42 ms 36936 KB Output is correct
33 Correct 31 ms 19176 KB Output is correct
34 Correct 93 ms 54344 KB Output is correct
35 Correct 111 ms 23276 KB Output is correct
36 Correct 87 ms 19640 KB Output is correct
37 Correct 72 ms 19124 KB Output is correct
38 Correct 47 ms 19048 KB Output is correct
39 Correct 54 ms 19332 KB Output is correct
40 Correct 110 ms 62000 KB Output is correct
41 Correct 73 ms 25408 KB Output is correct
42 Correct 54 ms 26056 KB Output is correct
43 Correct 70 ms 22320 KB Output is correct
44 Correct 83 ms 28984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14304 KB Output is correct
2 Correct 8 ms 14364 KB Output is correct
3 Correct 8 ms 14328 KB Output is correct
4 Correct 8 ms 14416 KB Output is correct
5 Correct 8 ms 14440 KB Output is correct
6 Correct 8 ms 14416 KB Output is correct
7 Correct 10 ms 14440 KB Output is correct
8 Correct 7 ms 14416 KB Output is correct
9 Correct 7 ms 14288 KB Output is correct
10 Correct 7 ms 14416 KB Output is correct
11 Correct 8 ms 14416 KB Output is correct
12 Correct 9 ms 14416 KB Output is correct
13 Correct 8 ms 14416 KB Output is correct
14 Correct 8 ms 14428 KB Output is correct
15 Correct 7 ms 14416 KB Output is correct
16 Correct 9 ms 14416 KB Output is correct
17 Correct 9 ms 14524 KB Output is correct
18 Correct 8 ms 14416 KB Output is correct
19 Correct 8 ms 14416 KB Output is correct
20 Correct 9 ms 14544 KB Output is correct
21 Correct 7 ms 14416 KB Output is correct
22 Correct 9 ms 14816 KB Output is correct
23 Correct 8 ms 14544 KB Output is correct
24 Correct 9 ms 14672 KB Output is correct
25 Correct 12 ms 14752 KB Output is correct
26 Correct 11 ms 14580 KB Output is correct
27 Correct 11 ms 14636 KB Output is correct
28 Correct 10 ms 14932 KB Output is correct
29 Correct 10 ms 14928 KB Output is correct
30 Correct 29 ms 18056 KB Output is correct
31 Correct 12 ms 15696 KB Output is correct
32 Correct 42 ms 36936 KB Output is correct
33 Correct 31 ms 19176 KB Output is correct
34 Correct 93 ms 54344 KB Output is correct
35 Correct 111 ms 23276 KB Output is correct
36 Correct 87 ms 19640 KB Output is correct
37 Correct 72 ms 19124 KB Output is correct
38 Correct 47 ms 19048 KB Output is correct
39 Correct 54 ms 19332 KB Output is correct
40 Correct 110 ms 62000 KB Output is correct
41 Correct 73 ms 25408 KB Output is correct
42 Correct 54 ms 26056 KB Output is correct
43 Correct 70 ms 22320 KB Output is correct
44 Correct 83 ms 28984 KB Output is correct
45 Correct 231 ms 34452 KB Output is correct
46 Correct 21 ms 15084 KB Output is correct
47 Correct 14 ms 15204 KB Output is correct
48 Correct 448 ms 86396 KB Output is correct
49 Correct 254 ms 57784 KB Output is correct
50 Runtime error 366 ms 262144 KB Execution killed with signal 9
51 Halted 0 ms 0 KB -