제출 #91642

#제출 시각아이디문제언어결과실행 시간메모리
91642chpipis경찰관과 강도 (BOI14_coprobber)C++11
100 / 100
1230 ms8436 KiB
#include "coprobber.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define fi first #define se second typedef pair<int, int> ii; bool mat[MAX_N + 5][MAX_N + 5]; bool win[MAX_N + 5][MAX_N + 5][2]; int deg[MAX_N + 5][MAX_N + 5][2]; int mv[MAX_N + 5][MAX_N + 5]; int n; int last_pos; 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++) mat[i][j] = A[i][j]; memset(win, false, sizeof win); queue<pair<ii, int> > q; for (int i = 0; i < n; i++) { win[i][i][0] = win[i][i][1] = true; q.push(mp(mp(i, i), 0)); q.push(mp(mp(i, i), 1)); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { deg[i][j][0] = 0; for (int nxt = 0; nxt < n; nxt++) { if (mat[i][nxt]) deg[i][j][0]++; } deg[i][j][1] = 1; for (int nxt = 0; nxt < n; nxt++) { if (mat[j][nxt]) deg[i][j][1]++; } } } while (!q.empty()) { int u = q.front().fi.fi; int v = q.front().fi.se; int who = q.front().se; q.pop(); if (who == 1) { for (int i = 0; i < n; i++) { if (mat[u][i]) { if (win[i][v][0]) continue; deg[i][v][0]--; if (deg[i][v][0] == 0) { win[i][v][0] = true; q.push(mp(mp(i, v), 0)); } } } } else { for (int j = 0; j < n; j++) { if (mat[v][j] || v == j) { if (win[u][j][1]) continue; mv[u][j] = v; win[u][j][1] = true; q.push(mp(mp(u, j), 1)); } } } } int pos = -1; for (int i = 0; i < n; i++) { bool yes = true; for (int j = 0; j < n; j++) yes &= win[j][i][1]; if (yes) pos = i; } last_pos = pos; return pos; } int nextMove(int R) { return last_pos = mv[R][last_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...