Submission #973468

#TimeUsernameProblemLanguageResultExecution timeMemory
973468steveonalexCop and Robber (BOI14_coprobber)C++17
100 / 100
365 ms8964 KiB
#include <bits/stdc++.h>
#include "coprobber.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return __lg(mask);}

// mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n"){
        for(auto item: container) cout << item << separator;
        cout << finish;
    }


template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 500;
const int INF = 1e9 + 69;

int graph[N][N];
bitset<N> edging[N];
int deg_cop[N][N], deg_crim[N][N];
int next_move[N][N];

int cop;

int current_subtask;

int n;

int start(int _n, bool A[N][N]){
    n = _n;

    for(int i = 0; i<n; ++i) for(int j= 0; j<n; ++j) edging[i][j] = A[i][j];

    for(int crim = 0; crim < n; ++crim) {
        int d = edging[crim].count();
        for(int cop = 0; cop < n; ++cop){
            if (crim == cop) continue;
            deg_cop[cop][crim] = 1; // in order for the (cop, crim) state to be winning, you only need it to reach one winning state
            deg_crim[cop][crim] = d; // in order for the (cop, crim) state to be winning, you need it to reach all winning state
        }
    }

    deque<array<int, 3>> q;
    for(int i = 0; i<n; ++i) {
        q.push_back({{i, i, 0}});
        q.push_back({{i, i, 1}});
    }

    int winning_state = 0;
    while(q.size()){
        array<int, 3> u = q.front(); q.pop_front();

        winning_state++;

        if (u[2] == 0){ // crim turn
            for(int i = 0; i < n; ++i) if (edging[u[1]][i] && deg_crim[u[0]][i]){
                deg_crim[u[0]][i]--;
                if (deg_crim[u[0]][i] == 0){
                    q.push_back({{u[0], i, 1}});
                }
            }
        }
        else{ // cop turn
            for(int i = 0; i < n; ++i) if ((i == u[0] || edging[u[0]][i]) && deg_cop[i][u[1]]){
                deg_cop[i][u[1]]--;
                if (deg_cop[i][u[1]] == 0){
                    next_move[i][u[1]] = u[0];
                    q.push_back({{i, u[1], 0}});
                }
            }
        }
    }

    cop = 0;
    if (winning_state == 2 * n * n) return 0;
    return -1;
}


int nextMove(int crim){
    return cop = next_move[cop][crim];
}


// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     int n, m; cin >> n >> m;

//     // int n; cin >> n;
//     bool a[N][N];
//     memset(a, 0, sizeof a);

//     for(int i = 0; i<m; ++i){
//         int u, v; cin >> u >> v;
//         a[u][v] = a[v][u] = 1;
//     }

//     int cop = start(n, a);
//     cout << "? " << cop << endl;

//     int crim; cin >> crim;
//     while(cop != crim){
//         cop = nextMove(crim);
//         if (cop == crim) break;
//         cout << "? " << cop << endl;
//         cin >> crim;
//     }

//     cout << "Crim caught!!!!" << endl;

//     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...