#include "train.h"
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::vector;
using ll = int;
using vi = vector<ll>;
using vii = vector<vi>;
using std::string;
using pii = std::pair<ll,ll>;
#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define ln "\n"
#define all(a) a.begin(), a.end()
#define mp std::make_pair
#define pb emplace_back
std::vector<int> wa_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
ll N = a.size();
vii edge(N);
rep(i,0,u.size()) edge[u[i]].pb(v[i]);
vi dp = r;
REP(t,0,N+100){
rep(i,0,N){
if(a[i] == 1){
for(auto next: edge[i]){
dp[i] |= dp[next];
}
}
else{
int val = 1;
for(auto next: edge[i]){
val &= dp[next];
}
dp[i] |= val;
}
}
}
rep(i,0,N) dp[i] = 1-dp[i];
REP(t,0,N+100){
rep(i,0,N){
if(a[i] == 0){
for(auto next: edge[i]){
dp[i] |= dp[next];
}
}
else{
int val = 1;
for(auto next: edge[i]){
val &= dp[next];
}
dp[i] |= val;
}
}
}
rep(i,0,N) dp[i] = 1-dp[i];
return dp;
}
std::vector<int> who_wins_1(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
ll N = a.size();
vi dp(N);
vii edge(N);
rep(i,0,u.size()) edge[u[i]].pb(v[i]);
per(i,N-1,0){
if(edge[i].size() == 1 && edge[i][0] == i){
dp[i] = r[i];
}
else if(edge[i].size() == 2){
if(a[i] == 1){
dp[i] = dp[i+1]|r[i];
}
else{
dp[i] = dp[i+1]&r[i];
}
}
else{
dp[i] = dp[i+1];
}
}
return dp;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
ll N = a.size();
assert(N <= 15);
vii edge(N);
rep(i,0,u.size()) edge[u[i]].pb(v[i]);
int sz = 1;
rep(i,0,N) sz *= 3;
vii dp(sz,vi(N,-1));
auto idx = [&](int visited, int imp){
int ret = 0;
rep(i,0,N){
ret = (visited&1)+(imp&1)+ret*3;
visited >>= 1;
imp >>= 1;
}
return ret;
};
std::function<int(int,int,int)> dfs = [&](int visited, int imp, int now){
int bit = idx(visited, imp);
if(dp[bit][now] != -1) return dp[bit][now];
int ret;
if(a[now] == 0){
ret = 1;
for(auto next: edge[now]){
if(visited & (1<<next)){
if(imp & (1<<next)) ret = 0;
}
else{
if(r[next] == 0) ret &= dfs(visited|(1<<next), now|(1<<next), next);
else ret &=dfs(visited|(1<<next), 0, next);
}
}
}
else{
ret = 0;
for(auto next: edge[now]){
if(visited & (1<<next)){
if(imp & (1<<next)) continue;
else ret = 1;
}
else{
if(r[next] == 0) ret |= dfs(visited|(1<<next), now|(1<<next), next);
else ret |=dfs(visited|(1<<next), 0, next);
}
}
}
return dp[bit][now] = ret;
};
vi ans(N);
rep(i,0,N){
int imp = 0;
if(r[i] == 0) imp = (1<<i);
ans[i] = dfs((1<<i), imp, i);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
724 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
190 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
1236 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
980 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
1236 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
724 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |