This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...) 1412
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
vector<int> who_wins(vector<int> own,
vector<int> charging,
vector<int> us,
vector<int> vs) {
int n = sz(own), m = sz(us);
vector<int> igraph[n];
for (int i = 0; i < m; i++) {
igraph[vs[i]].push_back(us[i]);
}
int pn = n;
n = n * (n + 1);
auto encode = [&](int u, int d) -> int { return d * pn + u; };
int dep[n]{};
{
for (auto& a : us) {
if (charging[a]) {
dep[encode(a, 0)]++;
} else {
for (int i = 0; i < pn; i++) {
dep[encode(a, i)]++;
}
}
}
}
bool qd[n]{};
vector<int> q;
auto push = [&](int u, bool f = false) -> void {
if (!qd[u] && (f || !dep[u])) {
qd[u] = true;
q.push_back(u);
}
};
for (int i = 0; i < pn; i++) {
if (charging[i]) {
push(encode(i, 0));
} else {
for (int j = 0; j <= pn; j++) {
push(encode(i, j));
}
}
}
vector<int> ans(n, -1);
while (sz(q)) {
int cur = q.back();
q.pop_back();
int j = cur / pn, u = cur % pn;
if (ans[cur] == -1) {
ans[cur] = false;
}
dbg(u, j, ans[cur]);
auto process = [&](int v, int en) -> void {
dep[en]--;
if (!own[v]) {
ans[en] = false;
push(en, true);
} else {
push(en);
}
};
if (charging[u]) {
assert(j == 0);
for (auto& v : igraph[u]) {
if (charging[v]) {
process(v, encode(v, 0));
} else {
for (int j = 0; j < pn; j++) {
process(v, encode(v, j));
}
}
}
} else {
for (auto& v : igraph[u]) {
if (charging[v]) {
if (j == 1) {
process(v, encode(v, 0));
}
} else if (j > 0) {
process(v, encode(v, j - 1));
}
}
}
}
for (auto& a : ans) {
if (a == -1) {
a = true;
}
}
vector<int> xans(pn);
for (int i = 0; i < pn; i++) {
xans[i] = ans[encode(i, 0)];
if (xans[i] == -1) {
xans[i] = true;
}
}
return xans;
}
Compilation message (stderr)
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:25:18: warning: statement has no effect [-Wunused-value]
25 | #define dbg(...) 1412
| ^~~~
train.cpp:88:3: note: in expansion of macro 'dbg'
88 | dbg(u, j, ans[cur]);
| ^~~
# | 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... |