이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010;
#include "train.h"
int dp[MAX_N], w[MAX_N], sum[MAX_N], inst[MAX_N], n;
int belong[MAX_N];
vector<int> edge[MAX_N];
bool dfs(int x, int s, int v = 0) {
static vector<int> stk;
if (dp[x] != -1) return dp[x] == s;
stk.pb(x);
inst[x] = true;
v += w[x];
sum[x] = v;
bool ret = true;
DE(x, s, v);
// A owns it
if (belong[x] == 1) {
dp[x] = 0;
for (int u : edge[x]) {
if (dp[u] != -1 && inst[u]) {
if (w[u] || sum[x] != sum[u]) {
dp[x] = 1;
break;
}
}
if (inst[u]) continue;
if (dfs(u, 1, v)) {
dp[x] = 1;
break;
}
}
DE(x, dp[x]);
if (dp[x] != s) {
ret = false;
dp[x] = -1;
}
}
else {
dp[x] = 1;
for (int u : edge[x]) {
if (dp[u] != -1 && inst[u]) {
if (w[u] == 0 && sum[x] == sum[u]) {
dp[x] = 0;
break;
}
}
if (inst[u]) continue;
if (dfs(u, 0, v)) {
DE(u, 0);
dp[x] = 0;
break;
}
}
DE(x, dp[x]);
if (dp[x] != s) {
ret = false;
dp[x] = -1;
}
}
stk.pop_back();
inst[x] = false;
dp[x] = -1;
return ret;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
n = a.size();
for (int i = 0;i < n;++i) {
w[i] = r[i];
belong[i] = a[i];
DE(i, w[i], belong[i]);
}
for (int i = 0;i < u.size();++i) {
edge[ u[i] ].pb( v[i] );
DE(u[i], v[i]);
}
vector<int> res(n);
for (int i = 0;i < n;++i) {
DE(i);
memset(dp, -1, sizeof(dp));
res[i] = dfs(i, 1);
}
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
train.cpp: In function 'bool dfs(int, int, int)':
train.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
train.cpp:36:2: note: in expansion of macro 'DE'
36 | DE(x, s, v);
| ^~
train.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
train.cpp:54:3: note: in expansion of macro 'DE'
54 | DE(x, dp[x]);
| ^~
train.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
train.cpp:71:5: note: in expansion of macro 'DE'
71 | DE(u, 0);
| ^~
train.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
train.cpp:76:3: note: in expansion of macro 'DE'
76 | DE(x, dp[x]);
| ^~
train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
train.cpp:95:3: note: in expansion of macro 'DE'
95 | DE(i, w[i], belong[i]);
| ^~
train.cpp:97:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for (int i = 0;i < u.size();++i) {
| ~~^~~~~~~~~~
train.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
train.cpp:99:3: note: in expansion of macro 'DE'
99 | DE(u[i], v[i]);
| ^~
train.cpp:14:17: warning: statement has no effect [-Wunused-value]
14 | #define DE(...) 0
| ^
train.cpp:105:3: note: in expansion of macro 'DE'
105 | DE(i);
| ^~
# | 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... |