Submission #1200137

#TimeUsernameProblemLanguageResultExecution timeMemory
1200137browntoad게임 (APIO22_game)C++20
0 / 100
1 ms1856 KiB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())

int n, k;
const ll maxn = 3e4+5;
const ll maxk = 1005;
const ll mod = 1e9+7;
const ll inf = (1ll<<60);
vector<int> g[maxn];
vector<int> rg[maxn];

bool ioth[maxk][maxn];
bool othi[maxk][maxn]; // walk reverse graph


void init(int N, int K) {
    n = N; k = K;
    REP(i, k-2){
        g[i].pb(i+1);
        rg[i+1].pb(i);
    }
    REP(i, k){
        FOR(j, i, k){
            ioth[i][j] = 1;
        }
        FOR(j, 0, i+1){
            othi[i][j] = 1;
        }
    }
}

bool dfs(int st, bool wh, int u){ // wh = 0: g, wh = 1, rg
    if (wh == 0){
        ioth[st][u] = 1;
        if (othi[st][u]){
            return 1;
        }
        for (auto v:g[u]){
            if (ioth[st][v]) continue;
            if (dfs(st, wh, v)) return 1;
        }
        return 0;
    }
    else{
        othi[st][u] = 1;
        if (ioth[st][u]){
            return 1;
        }
        for (auto v:rg[u]){
            if (othi[st][v]) continue;
            if (dfs(st, wh, v)) return 1;
        }
        return 0;
    }
}
int add_teleporter(int u, int v) {
    // self-loop: u = v
    if (u == v){
        if (u < k) return 1;
        return 0;
    }
    g[u].pb(v);
    rg[v].pb(u);

    REP(i, k){
        if (!ioth[i][u] || ioth[i][v]) continue;
        if (dfs(i, 0, v)) return 1;
    }
    REP(i, k){
        if (!othi[i][v] || othi[i][u]) continue;
        if (dfs(i, 1, u)) return 1;
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...