# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1068409 | Abito | Toy Train (IOI17_train) | C++17 | 4 ms | 1324 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 "train.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=5005;
int n;
bool b[2][N],dp[N],vis[N],a[N],c[N];
bool rec(int x){
if (vis[x]) return dp[x];
vis[x]=1;
if (a[x]){
if (b[0][x] && c[x]){
dp[x]=1;
// cout<<x<<endl;
}
if (b[1][x]){
if (a[x+1]) dp[x]|=rec(x+1);
else dp[x]|=!rec(x+1);
}
}
else{
if (b[0][x] && !c[x]) dp[x]=1;
if (b[1][x]){
if (!a[x+1]) dp[x]|=rec(x+1);
else dp[x]|=!rec(x+1);
}
}return dp[x];
}
std::vector<int32_t> who_wins(std::vector<int32_t> A, std::vector<int32_t> r, std::vector<int32_t> u, std::vector<int32_t> v) {
n=A.size();
for (int i=1;i<=n;i++) a[i]=A[i-1],c[i]=r[i-1];
for (int i=0;i<u.size();i++){
if (v[i]==u[i]) b[0][u[i]+1]=1;
else b[1][u[i]+1]=1;
}
//for (int i=1;i<=n;i++) cout<<b[0][i]<<' '<<b[1][i]<<endl;
vector<int32_t> ans(n);
for (int i=0;i<n;i++){
if (a[i+1]) ans[i]=rec(i+1);
else ans[i]=!rec(i+1);
}
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... |