# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
33536 | mohammad_kilani | Toy Train (IOI17_train) | C++14 | 2000 ms | 262144 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 ;
int dp[N][N];
vector<int> a, r;
vector<int> g[N];
bool solve(int i,int j){
if(r[i]) j = n;
if(j == 0) return 0;
if(dp[i][j] != -1) return dp[i][j];
dp[i][j] = 1;
if(!r[i]){
for(int k=0;k<g[i].size();k++){
int node = g[i][k];
if(solve(node,j-1) == 0) dp[i][j] = 0;
}
}
else{
bool can = false;
for(int k=0;k<g[i].size();k++){
int node = g[i][k];
if(solve(node,j-1) == 1) can = true;
}
dp[i][j] = can;
}
return dp[i][j];
}
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]);
memset(dp,-1,sizeof(dp));
for(int i=0;i<n;i++) ans.push_back(solve(i,n));
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... |