# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
122569 | SirCeness | Toy Train (IOI17_train) | C++14 | 2066 ms | 30032 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>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
list<int> adj[5003];
int sonuc[5003];
vector<int> a, r, u, v;
set<int> byendi;
int f(int node, set<int> barz){
//cout << "f(" << node << ")" << endl;
if (sonuc[node] != 0){
if (sonuc[node] == 1) return 1;
else {
if (barz.find(node) == barz.end()) return 1;
else return -1;
}
}
if (r[node]){
sonuc[node] = 1;
barz = byendi;
} else {
sonuc[node] = -1;
barz.insert(node);
}
int ans = a[node] ? -1 : 1;
for (list<int>::iterator it = adj[node].begin(); it != adj[node].end(); ++it){
if (*it == node) continue;
if (a[node]) ans = max(ans, f(*it, barz));
else ans = min(ans, f(*it, barz));
}
sonuc[node] = 0;
return ans;
}
vector<int> who_wins(vector<int> A, vector<int> R, vector<int> U, vector<int> V) {
a = A;
r = R;
u = U;
v = V;
for (int i = 0; i < u.size(); i++){
adj[u[i]].pb(v[i]);
}
vector<int> ans(a.size());
for (int i = 0; i < a.size(); i++) sonuc[i] = 0;
for (int i = 0; i < a.size(); i++){
int kendi = 0;
int baska = 0;
for (list<int>::iterator it = adj[i].begin(); it != adj[i].end(); ++it){
if (*it == i) kendi = 1;
else baska = 1;
}
if (kendi){
if (a[i] && r[i]) sonuc[i] = 1;
else if (!a[i] && !r[i]) sonuc[i] = -1, byendi.insert(i);
}
if (!baska){
if (r[i]) sonuc[i] = 1;
else sonuc[i] = -1, byendi.insert(i);
}
}
for (int i = 0; i < a.size(); i++){
if (sonuc[i] == 0){
sonuc[i] = f(i, byendi);
}
}
//for (int i = 0; i < a.size(); i++) cout << sonuc[i] << " "; cout << endl;
for (int i = 0; i < a.size(); i++) ans[i] = (sonuc[i] == 1) ? 1 : 0;
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... |