이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "coprobber.h"
#include <bits/stdc++.h>
using namespace std;
static int states[500005]; //police * 1000 + robber * 2 + (IF POLICE TURN)
static int degree[500005];
static int to[500005];
static vector<int> adj[500005];
static vector<int> rev[500005];
queue<int> can;
inline int g(int police, int robber, int turn){
return police * 1000 + robber * 2 + turn;
}
int pos;
int start(int N, bool A[MAX_N][MAX_N])
{
int n = N;
for(int u = 0;u < n;u++){
for(int v = 0;v < n;v++){
int s = g(u,v,0);
adj[s].push_back(g(u,v,1)); //Wait
for(int i = 0;i < n;i++){
if(A[u][i] == 1) adj[s].push_back(g(i,v,1));
}
s = g(u,v,1);
for(int i = 0;i < n;i++){
if(A[v][i] == 1) adj[s].push_back(g(u,i,0));
}
}
}
for(int i = 0;i < 500005;i++){
int u = i / 1000;
int v = (i / 2) % 500;
for(int j = 0;j < adj[i].size();j++){
int q = adj[i][j];
rev[q].push_back(i);
degree[i]++;
if(u == v){
states[i] = 1;
}
//cout << i << " " << q << "\n";
}
}
for(int i = 0;i < 500005;i++){
if(states[i] == 1){
can.push(i);
degree[i] = 0;
}
}
while(!can.empty()){
int t = can.front();
//cout << t << "\n";
can.pop();
for(int i = 0;i < rev[t].size();i++){
int s = rev[t][i];
if(states[s] == 0){
degree[s]--;
//cout << t << " " << s << " " << degree[s] << "\n";
if(s % 2 == 0){
can.push(s);
states[s] = 1;
degree[s] = 0;
to[s] = t;
//cout << s << " " << t << "\n";
}
else if(degree[s] == 0){
can.push(s);
states[s] = 1;
}
}
}
}
for(int u = 0;u < n;u++){
bool can = true;
for(int v = 0;v < n;v++){
if(states[g(u,v,0)] == 0){
can = false;
break;
}
}
if(can){
pos = u;
return u;
}
}
return -1;
}
int nextMove(int R)
{
int cur = g(pos,R,0);
int t = to[cur];
t /= 1000;
//cout << t << " " << R << "\n";
pos = t;
return t;
}
컴파일 시 표준 에러 (stderr) 메시지
coprobber.cpp: In function 'int start(int, bool (*)[500])':
coprobber.cpp:34:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0;j < adj[i].size();j++){
~~^~~~~~~~~~~~~~~
coprobber.cpp:55:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0;i < rev[t].size();i++){
~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |