# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
390279 | Keshi | 장난감 기차 (IOI17_train) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//In the name of God
#include <bits/stdc++.h>
#include "train.h"
using namespace std;
typedef int ll;
typedef pair<ll, ll> pll;
const ll maxn = 5100;
const ll mod = 1e9 + 7;
const ll inf = 1e9;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
ll n, m;
vector<ll> g[maxn], gp[maxn];
ll ok[maxn][maxn], cnt[maxn], q[maxn], w[maxn];
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> v, vector<int> u){
n = Sz(a);
m = Sz(v);
vector<int> res(n), res2(n);
for(ll i = 0; i < m; i++){
g[v[i]].pb(u[i]);
gp[u[i]].pb(v[i]);
}
for(ll i = 0; i < n; i++){
if(!r[i]) continue;
fill(cnt, cnt + maxn, 0);
ll l = 0, r = 0;
ok[i][q[r++] = i] = 1;
while(l < r){
ll v = q[l++];
for(ll u : gp[v]){
cnt[u]++;
if(ok[i][u]) continue;
if(a[u]) ok[Qi][q[r++] = u] = 1;
else if(cnt[u] == Sz(g[u])) ok[i][q[r++] = u] = 1;
}
}
if(a[i]){
if(cnt[i]) w[i] = 1;
}
else{
if(cnt[i] == Sz(g[i])) w[i] = 1;
}
}
fill(cnt, cnt + n, 0);
ll l = 0, qr = 0;
for(ll i = 0; i < n; i++){
if(w[i]){
res[q[qr++] = i] = 1;
continue;
}
if(!r[i]) continue;
for(ll j : g[i]){
if(i == j) cnt[i]++;
}
if(cnt[i] == Sz(g[i]) || (a[i] && cnt[i])) res[q[qr++] = i] = 1;
}
while(l < qr){
ll v = q[l++];
for(ll u : gp[v]){
cnt[u]++;
if(res[u]) continue;
if(a[u] || cnt[u] == Sz(g[u])) res[q[qr++] = u] = 1;
}
}
return res;
}