이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "coprobber.h"
#include <bits/stdc++.h>
using namespace std;
int kol [510][510][2];
int st [510][510][2];
queue < pair <int, pair <int, int> > > kju;
int mov [510][510];
int curr;
int start (int n, bool l [MAX_N][MAX_N]){
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
int uk=0;
for (int k=0; k<n; k++) uk+=l [j][k];
kol [i][j][0]=1;
kol [i][j][1]=uk;
if (i==j){
kju.push ({0, {i, j}});
kju.push ({1, {i, j}});
}
}
}
while (!kju.empty()){
int m=kju.front().first;
int a=kju.front().second.first;
int b=kju.front().second.second;
//cout << m << " " << a << " " << b << endl;
st [m][a][b]=1;
if (m==0){
for (int i=0; i<n; i++){
if (!l [i][b]) continue;
kol [a][i][1]--;
if (kol [a][i][1]==0){
kju.push ({1, {a, i}});
}
}
}
else {
for (int i=0; i<n; i++){
if (!l [i][a]) continue;
kol [i][b][0]--;
if (kol [i][b][0]==0){
kju.push ({0, {i, b}});
mov [i][b]=a;
}
}
}
kju.pop();
}
for (int i=0; i<n; i++){
int uk=0;
for (int j=0; j<n; j++) uk+=st [1][i][j];
if (uk==n) return curr=i;
}
return -1;
}
int nextMove (int x){
return curr=mov [curr][x];
}
/*int a [510][510];
int main(){
int n; cin >> n;
for (int i=0; i<n; i++){
for (int j=0; j<n; j++) cin >> a [i][j];
}
cout << start (n, a) << endl;
while (true){
int x; cin >> x;
if (x==-1) break;
cout << nextMove (x) << endl;
}
return 0;
}*/
# | 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... |