Submission #956904

#TimeUsernameProblemLanguageResultExecution timeMemory
956904GrindMachineCop and Robber (BOI14_coprobber)C++17
0 / 100
884 ms4128 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define pb push_back #define endl '\n' #define sz(a) a.size() #define setbits(x) __builtin_popcountll(x) #define ff first #define ss second #define conts continue #define ceil2(x, y) ((x + y - 1) / (y)) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define yes cout << "Yes" << endl #define no cout << "No" << endl #define rep(i, n) for(int i = 0; i < n; ++i) #define rep1(i, n) for(int i = 1; i <= n; ++i) #define rev(i, s, e) for(int i = s; i >= e; --i) #define trav(i, a) for(auto &i : a) template<typename T> void amin(T &a, T b) { a = min(a, b); } template<typename T> void amax(T &a, T b) { a = max(a, b); } #ifdef LOCAL #include "debug.h" #else #define debug(x) 42 #endif /* refs: edi */ const int MOD = 1e9 + 7; const int N = 1e5 + 5; const int inf1 = int(1e9) + 5; const ll inf2 = ll(1e18) + 5; #include "coprobber.h" int n; int dp[MAX_N][MAX_N][2]; bool a[MAX_N][MAX_N]; vector<int> adj[MAX_N]; int pos; int start(int n_, bool a_[MAX_N][MAX_N]) { n = n_; rep(i,MAX_N){ adj[i].clear(); } rep(i,MAX_N){ rep(j,MAX_N){ a[i][j] = a_[i][j]; if(a[i][j]){ adj[i].pb(j); } } } memset(dp,-1,sizeof dp); queue<array<int,3>> q; rep(i,n){ dp[i][i][0] = 1; dp[i][i][1] = 0; q.push({i,i,0}); q.push({i,i,1}); } rep(iter,inf1){ int change = 0; rep(i,n){ rep(j,n){ rep(k,2){ if(dp[i][j][k] != -1) conts; int lose = 0, win = 0, draw = 0; if(k == 0){ trav(v,adj[i]){ auto val = dp[v][j][k^1]; if(val == -1) draw++; if(val == 0) lose++; if(val == 1) win++; } { int v = i; auto val = dp[v][j][k^1]; if(val == -1) draw++; if(val == 0) lose++; if(val == 1) win++; } if(lose >= 1){ dp[i][j][k] = 1; change++; } else{ if(draw == 0){ dp[i][j][k] = 0; change++; } } } else{ trav(v,adj[j]){ auto val = dp[i][v][k^1]; if(val == -1) draw++; if(val == 0) lose++; if(val == 1) win++; } if(lose >= 1){ dp[i][j][k] = 1; change++; } else{ if(draw == 0){ dp[i][j][k] = 0; change++; } } } } } } if(!change){ break; } } // int win_cnt[n][n][2], lose_cnt[n][n][2]; // memset(win_cnt,0,sizeof win_cnt); // memset(lose_cnt,0,sizeof lose_cnt); // rep(i,n){ // rep(j,n){ // if(i == j) conts; // rep(k,2){ // if(k == 0){ // win_cnt[i][j][k] = sz(adj[i])+1; // } // else{ // lose_cnt[i][j][k] = sz(adj[j]); // } // } // } // } // while(!q.empty()){ // auto [i,j,k] = q.front(); // q.pop(); // if(k == 0){ // // police wins, sub 1 from lose_cnt[i][v][k^1] // if(dp[i][j][k]){ // trav(v,adj[j]){ // if(dp[i][v][k^1] == -1){ // lose_cnt[i][v][k^1]--; // if(!lose_cnt[i][v][k^1]){ // q.push({i,v,k^1}); // dp[i][v][k^1] = 0; // } // } // } // } // // police loses, add unvis adj robber states // else{ // trav(v,adj[j]){ // if(dp[i][v][k^1] == -1){ // q.push({i,v,k^1}); // dp[i][v][k^1] = 1; // } // } // } // } // else{ // // robber loses, add unvis adj police states // if(!dp[i][j][k]){ // trav(v,adj[i]){ // if(dp[v][j][k^1] == -1){ // q.push({v,j,k^1}); // dp[v][j][k^1] = 1; // } // } // { // int v = j; // if(dp[v][j][k^1] == -1){ // q.push({v,j,k^1}); // dp[v][j][k^1] = 1; // } // } // } // // robber wins, sub 1 from win_cnt[v][j][k^1] // else{ // trav(v,adj[i]){ // if(dp[v][j][k^1] == -1){ // win_cnt[v][j][k^1]--; // if(!win_cnt[v][j][k^1]){ // q.push({v,j,k^1}); // dp[v][j][k^1] = 0; // } // } // } // { // int v = i; // if(dp[v][j][k^1] == -1){ // win_cnt[v][j][k^1]--; // if(!win_cnt[v][j][k^1]){ // q.push({v,j,k^1}); // dp[v][j][k^1] = 0; // } // } // } // } // } // } pos = -1; rep(u,n){ bool ok = true; rep(v,n){ if(dp[u][v][0] != 1){ ok = false; } } if(ok){ pos = u; } } return pos; } int nextMove(int v) { assert(dp[pos][v][0] == 1); trav(u,adj[pos]){ if(dp[u][v][1] == 0){ pos = u; return pos; } } { int u = pos; if(dp[u][v][1] == 0){ pos = u; return pos; } } assert(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...