Submission #1047940

#TimeUsernameProblemLanguageResultExecution timeMemory
1047940LoboCop and Robber (BOI14_coprobber)C++17
100 / 100
205 ms9816 KiB
#include "coprobber.h"
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 10;
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxn = 505;

// dp[i][j][t]
// i -> policial
// j -> ladrao
// t = 0 -> vez do policial
// t = 1 -> vez do ladrao

int n, dp[maxn][maxn][2], next0[maxn][maxn], left1[maxn][maxn];
vector<int> g[maxn];
int C;
int start(int N, bool A[MAX_N][MAX_N])
{
    n = N;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(A[i][j] == 1) g[i].pb(j);
        }
    }
    queue<pair<pair<int,int>,int>> q;
    for(int i = 0; i < n; i++) {
        q.push(mp(mp(i,i),0));
        q.push(mp(mp(i,i),1));
        dp[i][i][0] = dp[i][i][1] = 1;
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            left1[i][j] = g[j].size();
        }
    }
    // ta na queue -> policial ganha nessa posicao, faz o push
    while(q.size()) {
        int i = q.front().fr.fr;
        int j = q.front().fr.sc;
        int t = q.front().sc;
        q.pop();
        if(t == 1) {
            for(auto v : g[i]) {
                if(dp[v][j][0] == 0) {
                    next0[v][j] = i; 
                    dp[v][j][0] = 1;
                    q.push(mp(mp(v,j),0));
                }
            }
            if(dp[i][j][0] == 0) {
                next0[i][j] = i; 
                dp[i][j][0] = 1;
                q.push(mp(mp(i,j),0));
            }
        }
        else {
            for(auto v : g[j]) {
                left1[i][v]--;

                if(dp[i][v][1] == 0 and left1[i][v] == 0) {
                    dp[i][v][1] = 1;
                    q.push(mp(mp(i,v),1));
                }
            }
        }
    }

    for(int i = 0; i < n; i++) {
        int qtd1 = 0;
        for(int j = 0; j < n; j++) {
            qtd1+= dp[i][j][0];
        }
        if(qtd1 == n) {
            C = i;
            return i;
        }
    }
    return -1;
}

int nextMove(int R)
{
    return C = next0[C][R];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...