이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "train.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef int ll;
#define MAX 6000
vector<ll> A, s;
ll N, M;
vector<ll> adj[MAX], rev[MAX], deg, d;
ll mp[MAX][MAX];
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
ll i;
A = a;
N = a.size();
M = u.size();
vector<ll> res, ans;
ans.resize(N);
for (i = 0; i < N; i++) if (r[i]) s.push_back(i);
for (i = 0; i < M; i++) adj[u[i]].push_back(v[i]), rev[v[i]].push_back(u[i]);
ll T;
for (T = 1; T <= N; T++) {
d.clear();
d.resize(N);
res.clear();
res.resize(N);
for (i = 0; i < N; i++) {
if (ans[i]) continue;
for (auto x : adj[i]) {
if (ans[x]) continue;
d[i]++;
}
}
deg = d;
queue<ll> q;
for (auto st : s) {
if (ans[st]) continue;
q.push(st);
res[st] = 1;
}
ll j;
while (!q.empty()) {
ll t = q.front();
q.pop();
for (auto x : rev[t]) {
if (ans[x]) continue;
if (res[x]) continue;
deg[x]--;
if (a[x]) q.push(x), res[x] = 1;
else if (deg[x] <= 0) q.push(x), res[x] = 1;
}
}
//impossible
deg = d;
vector<ll> imp;
for (i = 0; i < N; i++) if (!res[i]) imp.push_back(i);
while (!q.empty()) q.pop();
for (auto st : imp) {
if (ans[st]) continue;
q.push(st);
ans[st] = 1;
}
while (!q.empty()) {
ll t = q.front();
q.pop();
for (auto x : rev[t]) {
if (ans[x]) continue;
deg[x]--;
if (!a[x]) q.push(x), ans[x] = 1;
else if (deg[x] <= 0) q.push(x), ans[x] = 1;
}
}
}
for (i = 0; i < N; i++) ans[i] = !ans[i];
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:48:6: warning: unused variable 'j' [-Wunused-variable]
48 | ll j;
| ^
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |