이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "coprobber.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 500;
// const int MAX_N = 500;
int N, st, in[MX][MX];
bitset<MX> adj[MX];
int dist[MX][MX][2];
int start(int n, bool A[MAX_N][MAX_N]) {
N = n;
F0R(i,N) F0R(j,N) {
adj[i][j] = A[i][j];
dist[i][j][0] = dist[i][j][1] = MOD;
}
queue<array<int,3>> q;
F0R(i,N) F0R(j,2) {
dist[i][i][j] = 0;
q.push({i,i,j});
}
F0R(i,N) F0R(j,N) in[i][j] = adj[j].count();
while (sz(q)) {
auto a = q.front(); q.pop();
int cdist = dist[a[0]][a[1]][a[2]];
if (a[2] == 1) {
F0R(i,N) if ((i == a[0] || adj[i][a[0]]) && dist[i][a[1]][0] == MOD) {
dist[i][a[1]][0] = cdist+1;
q.push({i,a[1],0});
}
} else {
F0R(i,N) if (adj[a[1]][i] && dist[a[0]][i][1] == MOD) {
in[a[0]][i] --;
if (in[a[0]][i] == 0) {
dist[a[0]][i][1] = cdist+1;
q.push({a[0],i,1});
}
}
}
}
//F0R(i,N) F0R(j,N) F0R(k,2) cout << i << " " << j << " " << k << " " << dist[i][j][k] << "\n";
F0R(i,N) {
bool ok = 1;
F0R(j,N) if (dist[i][j][0] == MOD) ok = 0;
if (ok) return st = i;
}
return -1;
}
int nextMove(int R) {
F0R(i,N) if (i == st || adj[st][i])
if (dist[i][R][1] < dist[st][R][0])
return st = i;
return -1;
}
# | 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... |