Submission #1038261

# Submission time Handle Problem Language Result Execution time Memory
1038261 2024-07-29T15:02:21 Z _8_8_ Game (APIO22_game) C++17
30 / 100
1014 ms 262144 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;
void build(int v = 1,int tl = 0,int tr = k - 1) {
    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);
    build(v + v + 1,tm + 1,tr);
}
void init(int n, int K) {
    k = K;
    for(int i = 0;i <= k - 2;i++) {
        g[i].push_back(i + 1);
        gr[i + 1].push_back(i);
    }
    build();
}
bool CYC = false;
bool check = false;
int vall[N],valr[N];
void add(int x,int y,int v = 1,int tl = 0,int tr = k - 1) {
    if(CYC) return;
    int tm = (tl + tr) >> 1;
    bool ok = false,ok1 = false;
    function<void(int)> dfs = [&](int u){
        R[v].insert(u);
        valr[u] = max(valr[u],tm);
        ok = 1;
        if(L[v].find(u) != L[v].end()) {
            CYC = 1;
            return;
        }
        for(int to:g[u]) {
            if(valr[to] > tm) continue;
            if(R[v].find(to) == R[v].end()) {
                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(R[v].find(y) == R[v].end() && valr[y] <= tm) dfs(y);
        if(tl != tr) add(x,y,v + v + 1,tm + 1,tr);
    } else {
        if(tl != tr) add(x,y,v + v,tl,tm);
    }
}
void addl(int x,int y,int v = 1,int tl = 0,int tr = k - 1) {
    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()) {
                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()) dfs1(x);
        if(tl != tr) addl(x,y,v + v,tl,tm);
    } else {
        if(tl != tr) addl(x,y,v+v+1,tm+1,tr);
    }
}
int add_teleporter(int u, int v) {
    if(max(u,v) <= k - 1) {
        if(u >= v) {
            CYC = 1;
            return 1;
        }
        return 0;
    }
    if(!check) {
        addl(13,14);  
        add(k-2,k-1);
        check = 1;
    }
    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)':
game.cpp:37:21: warning: unused variable 'ok1' [-Wunused-variable]
   37 |     bool ok = false,ok1 = false;
      |                     ^~~
# Verdict Execution time Memory Grader output
1 Correct 25 ms 98904 KB Output is correct
2 Correct 29 ms 98904 KB Output is correct
3 Correct 26 ms 98952 KB Output is correct
4 Correct 25 ms 99040 KB Output is correct
5 Correct 25 ms 98904 KB Output is correct
6 Correct 25 ms 98904 KB Output is correct
7 Correct 26 ms 98904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 98904 KB Output is correct
2 Correct 29 ms 98904 KB Output is correct
3 Correct 26 ms 98952 KB Output is correct
4 Correct 25 ms 99040 KB Output is correct
5 Correct 25 ms 98904 KB Output is correct
6 Correct 25 ms 98904 KB Output is correct
7 Correct 26 ms 98904 KB Output is correct
8 Correct 25 ms 98904 KB Output is correct
9 Correct 29 ms 98904 KB Output is correct
10 Correct 28 ms 98848 KB Output is correct
11 Correct 25 ms 98904 KB Output is correct
12 Correct 27 ms 98904 KB Output is correct
13 Correct 29 ms 98904 KB Output is correct
14 Correct 29 ms 99280 KB Output is correct
15 Correct 25 ms 99160 KB Output is correct
16 Correct 27 ms 98904 KB Output is correct
17 Correct 28 ms 98904 KB Output is correct
18 Correct 24 ms 98904 KB Output is correct
19 Correct 26 ms 98904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 98904 KB Output is correct
2 Correct 29 ms 98904 KB Output is correct
3 Correct 26 ms 98952 KB Output is correct
4 Correct 25 ms 99040 KB Output is correct
5 Correct 25 ms 98904 KB Output is correct
6 Correct 25 ms 98904 KB Output is correct
7 Correct 26 ms 98904 KB Output is correct
8 Correct 25 ms 98904 KB Output is correct
9 Correct 29 ms 98904 KB Output is correct
10 Correct 28 ms 98848 KB Output is correct
11 Correct 25 ms 98904 KB Output is correct
12 Correct 27 ms 98904 KB Output is correct
13 Correct 29 ms 98904 KB Output is correct
14 Correct 29 ms 99280 KB Output is correct
15 Correct 25 ms 99160 KB Output is correct
16 Correct 27 ms 98904 KB Output is correct
17 Correct 28 ms 98904 KB Output is correct
18 Correct 24 ms 98904 KB Output is correct
19 Correct 26 ms 98904 KB Output is correct
20 Correct 27 ms 98900 KB Output is correct
21 Correct 26 ms 98904 KB Output is correct
22 Correct 33 ms 99160 KB Output is correct
23 Correct 26 ms 99092 KB Output is correct
24 Correct 99 ms 121604 KB Output is correct
25 Correct 89 ms 108880 KB Output is correct
26 Correct 35 ms 99664 KB Output is correct
27 Correct 37 ms 100176 KB Output is correct
28 Correct 39 ms 100428 KB Output is correct
29 Correct 39 ms 100432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 98904 KB Output is correct
2 Correct 29 ms 98904 KB Output is correct
3 Correct 26 ms 98952 KB Output is correct
4 Correct 25 ms 99040 KB Output is correct
5 Correct 25 ms 98904 KB Output is correct
6 Correct 25 ms 98904 KB Output is correct
7 Correct 26 ms 98904 KB Output is correct
8 Correct 25 ms 98904 KB Output is correct
9 Correct 29 ms 98904 KB Output is correct
10 Correct 28 ms 98848 KB Output is correct
11 Correct 25 ms 98904 KB Output is correct
12 Correct 27 ms 98904 KB Output is correct
13 Correct 29 ms 98904 KB Output is correct
14 Correct 29 ms 99280 KB Output is correct
15 Correct 25 ms 99160 KB Output is correct
16 Correct 27 ms 98904 KB Output is correct
17 Correct 28 ms 98904 KB Output is correct
18 Correct 24 ms 98904 KB Output is correct
19 Correct 26 ms 98904 KB Output is correct
20 Correct 27 ms 98900 KB Output is correct
21 Correct 26 ms 98904 KB Output is correct
22 Correct 33 ms 99160 KB Output is correct
23 Correct 26 ms 99092 KB Output is correct
24 Correct 99 ms 121604 KB Output is correct
25 Correct 89 ms 108880 KB Output is correct
26 Correct 35 ms 99664 KB Output is correct
27 Correct 37 ms 100176 KB Output is correct
28 Correct 39 ms 100428 KB Output is correct
29 Correct 39 ms 100432 KB Output is correct
30 Correct 64 ms 100708 KB Output is correct
31 Correct 47 ms 100612 KB Output is correct
32 Correct 94 ms 105804 KB Output is correct
33 Correct 49 ms 101844 KB Output is correct
34 Runtime error 1014 ms 262144 KB Execution killed with signal 9
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 98904 KB Output is correct
2 Correct 29 ms 98904 KB Output is correct
3 Correct 26 ms 98952 KB Output is correct
4 Correct 25 ms 99040 KB Output is correct
5 Correct 25 ms 98904 KB Output is correct
6 Correct 25 ms 98904 KB Output is correct
7 Correct 26 ms 98904 KB Output is correct
8 Correct 25 ms 98904 KB Output is correct
9 Correct 29 ms 98904 KB Output is correct
10 Correct 28 ms 98848 KB Output is correct
11 Correct 25 ms 98904 KB Output is correct
12 Correct 27 ms 98904 KB Output is correct
13 Correct 29 ms 98904 KB Output is correct
14 Correct 29 ms 99280 KB Output is correct
15 Correct 25 ms 99160 KB Output is correct
16 Correct 27 ms 98904 KB Output is correct
17 Correct 28 ms 98904 KB Output is correct
18 Correct 24 ms 98904 KB Output is correct
19 Correct 26 ms 98904 KB Output is correct
20 Correct 27 ms 98900 KB Output is correct
21 Correct 26 ms 98904 KB Output is correct
22 Correct 33 ms 99160 KB Output is correct
23 Correct 26 ms 99092 KB Output is correct
24 Correct 99 ms 121604 KB Output is correct
25 Correct 89 ms 108880 KB Output is correct
26 Correct 35 ms 99664 KB Output is correct
27 Correct 37 ms 100176 KB Output is correct
28 Correct 39 ms 100428 KB Output is correct
29 Correct 39 ms 100432 KB Output is correct
30 Correct 64 ms 100708 KB Output is correct
31 Correct 47 ms 100612 KB Output is correct
32 Correct 94 ms 105804 KB Output is correct
33 Correct 49 ms 101844 KB Output is correct
34 Runtime error 1014 ms 262144 KB Execution killed with signal 9
35 Halted 0 ms 0 KB -