# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
33544 | mohammad_kilani | Toy Train (IOI17_train) | C++14 | 2000 ms | 3116 KiB |
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/stdc++.h>
#include "train.h"
using namespace std;
const int N = 5010;
int n ;
bitset< N > dp , vis , win ;
vector<int> g[N] , a , r;
bool solve(int i, int j){
if(r[i]) return 1;
if(i == j && !a[i]) return 0;
if(vis[i]) return dp[i];
vis[i] = 1;
dp[i] = 1;
if(!a[i]){
for(int k=0;k<g[i].size();k++){
int node = g[i][k];
if(solve(node,j) == 0) dp[i] = 0;
}
}
else{
bool can = false;
for(int k=0;k<g[i].size();k++){
int node = g[i][k];
if(node != j && solve(node,j) == 1) can = true;
}
dp[i] = can;
}
return dp[i];
}
bool solve2(int i){
if(win[i] == 0) return 0;
if(vis[i]) return dp[i];
vis[i] = 1;
dp[i] = 1;
if(!a[i]){
for(int k=0;k<g[i].size();k++){
int node = g[i][k];
if(solve2(node) == 0) dp[i] = 0;
}
}
else{
bool can = false;
for(int k=0;k<g[i].size();k++){
int node = g[i][k];
if(solve2(node) == 1) can = true;
}
dp[i] = can;
}
return dp[i];
}
std::vector<int> who_wins(std::vector<int> A, std::vector<int> R, std::vector<int> u, std::vector<int> v) {
vector<int> ans;
a = A;
r = R;;
n = a.size();
for(int i=0;i<u.size();i++) g[u[i]].push_back(v[i]);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++) vis[j] = 0 ;
bool can = 1;
for(int j=0;j<g[i].size();j++){
if(solve(g[i][j],i) == 0) can = 0;
}
win[i] = can;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++) vis[j] = 0 ;
bool can = 1;
if(solve2(i) == 0) can = 0;
win[i] = can;
ans.push_back(win[i]);
}
return ans;
}
Compilation message (stderr)
# | 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... |