Submission #235680

#TimeUsernameProblemLanguageResultExecution timeMemory
235680alishahali1382Cop and Robber (BOI14_coprobber)C++14
100 / 100
512 ms7624 KiB
#include <bits/stdc++.h> #include "coprobber.h" #pragma GCC optimize ("O2") #pragma GCC optimize ("unroll-loops") //#pragma GCC optimize("no-stack-protector,fast-math") using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<pii, int> piii; typedef pair<ll, ll> pll; #define debug(x) cerr<<#x<<'='<<(x)<<endl; #define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl; #define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl; #define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;} #define all(x) x.begin(), x.end() #define pb push_back #define kill(x) return cout<<x<<'\n', 0; int n, m, k, u, v, x, y, t, a, b, pos; int dp[2][MAX_N][MAX_N]; // dp0:cop dp1:robber int cnt[MAX_N][MAX_N], deg[MAX_N]; queue<piii> Q; int start(int n, bool A[MAX_N][MAX_N]){ for (int i=0; i<n; i++) for (int j=0; j<n; j++) deg[i]+=A[i][j]; for (int i=0; i<n; i++) for (int j=0; j<n; j++) cnt[i][j]=deg[j]; memset(dp, -1, sizeof(dp)); for (int i=0; i<n; i++){ Q.push({{i, i}, 0}); Q.push({{i, i}, 1}); dp[0][i][i]=i; dp[1][i][i]=i; } while (Q.size()){ int u=Q.front().first.first, v=Q.front().first.second, turn=Q.front().second; Q.pop(); if (turn){ for (int i=0; i<n; i++) if ((A[i][u] || i==u) && dp[0][i][v]==-1){ dp[0][i][v]=u; Q.push({{i, v}, 0}); } } else{ for (int i=0; i<n; i++) if (A[i][v] && dp[1][u][i]==-1 && !--cnt[u][i]){ dp[1][u][i]=v; Q.push({{u, i}, 1}); } } } for (int i=0; i<n; i++){ bool ok=1; for (int j=0; j<n && ok; j++) if (dp[0][i][j]==-1) ok=0; if (!ok) continue ; return pos=i; } return -1; } int nextMove(int R){ pos=dp[0][pos][R]; return pos; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...