#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;
}
constexpr int sz = pow(3,15);
int dp[sz][15] = {-1};
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]);
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 |
949 ms |
262144 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
3164 KB |
3rd lines differ - on the 2nd token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1519 ms |
262144 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
853 ms |
262144 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1179 ms |
262144 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
949 ms |
262144 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |