제출 #250551

#제출 시각아이디문제언어결과실행 시간메모리
250551opukittpceno_hhr경찰관과 강도 (BOI14_coprobber)C++17
60 / 100
765 ms262148 KiB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

#define MAX_N 500

// modify the following functions
// you can define global variables and functions

using namespace std;

const int M = 500 * 500 * 2;

int loose[M];
int win[M];
int cnt[M];
int turn[M];
int used[M];
vector<int> g[M];
vector<int> ig[M];

void dfs(int v) {
    used[v] = 1;
    for (auto i : ig[v]) {
        if (used[i]) continue;
        if (loose[v]) {
            win[i] = 1;
            turn[i] = v;
            dfs(i);
        } else {
            cnt[i]--;
            if (cnt[i] == 0) {
                loose[i] = 1;
                dfs(i);
            }
        }
    }
}

int Nn, Cn;

int start(int N, bool a[MAX_N][MAX_N]) {
    int n = N;
    Nn = N;
    Cn = -1;
    for (int k = 0; k < 2 * n * n; k++) {
        int t = k / (n * n);
        int st = k % (n * n);
        int i = st / n;
        int j = st % n;
        if (t == 0) {
            //our move
            for (int to = 0; to < n; to++) {
                if (a[i][to] || i == to) {
                    g[k].push_back(n * n + (to * n + j));
                }
            }
        } else {
            //robber move
            for (int to = 0; to < n; to++) {
                if (a[j][to]) {
                    g[k].push_back(i * n + to);
                }
            }
        }
        cnt[k] = (int)g[k].size();
    }
    for (int i = 0; i < n; i++) {
        loose[n * n + i * n + i] = 1;
    }
    for (int i = 0; i < n; i++) {
        win[i * n + i] = 1;
    }
    for (int i = 0; i < 2 * n * n; i++) {
        for (auto j : g[i]) {
            ig[j].push_back(i);
        }
    }
    for (int i = 0; i < 2 * n * n; i++) {
        if (!used[i] && (win[i] || loose[i])) {
            dfs(i);
        }
    }
    for (int i = 0; i < n; i++) {
        int ok = 1;
        for (int j = 0; j < n; j++) {
            ok &= win[i * n + j];
        }
        if (ok) {
            Cn = i;
            return i;
        }
    }
    return -1;
}

int nextMove(int r) {
    if (!win[Cn * Nn + r]) {
        return -1;
    }
    int next_state = turn[Cn * Nn + r];
    next_state %= (Nn * Nn);
    Cn = next_state / Nn;
    return Cn;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...