Submission #294214

#TimeUsernameProblemLanguageResultExecution timeMemory
294214ASDF123Toy Train (IOI17_train)C++14
5 / 100
2097 ms2048 KiB
//#include "train.h" #include <bits/stdc++.h> #define fr first #define sc second #define pii pair<int, int> #define szof(s) (int)s.size() #define all(s) s.begin(), s.end() using namespace std; typedef vector<int> vi; const int MAXN = 5001; struct LineSolve { vi a, r, u, v; int n, m; vector <int> g[MAXN]; vector <int> rg[MAXN]; LineSolve (vi A, vi R, vi U, vi V) { a = A; r = R; u = U; v = V; n = szof(a); m = szof(u); for (int i = 0; i < m; i++) { g[u[i]].push_back(v[i]); rg[v[i]].push_back(u[i]); } } int calc(int pos) { int v = pos, can = n; while (1) { if (r[v]) { can = n; } if (!can) { return 0; } if (szof(g[v]) == 1) { if (g[v][0] == v) { if (r[v]) { return 1; } else { return 0; } } else { v = g[v][0]; can--; continue; } } else { // 2 types of edges if (a[v]) { // Arezou if (r[v]) { return 1; } else { v = (g[v][0] == v ? g[v][1] : g[v][0]); can--; continue; } } else { // Borzou if (r[v] == 0) { return 0; } else { v = (g[v][0] == v ? g[v][1] : g[v][0]); can--; continue; } } } } } void solve(vector <int> &ans) { for (int i = 0; i < n; i++) { ans[i] = calc(i); } } }; vi who_wins(vi a, vi r, vi u, vi v) { vi res(a.size(), -1); LineSolve subtask1(a, r, u, v); subtask1.solve(res); return res; } //signed main() { //int n, m; //cin >> n >> m; //vector <int> a(n), r(n); //vector <int> u(m), v(m); //for (int i = 0; i < n; i++) { //cin >> a[i]; //} //for (int i = 0; i < n; i++) { //cin >> r[i]; //} //for (int i = 0; i < m; i++) { //cin >> u[i]; //} //for (int i = 0; i < m; i++) { //cin >> v[i]; //} //vector <int> ans = who_wins(a, r, u, v); //for (int i = 0; i < n; i++) { //cout << i << ": " << ans[i] << endl; //} //} /* 7 7 0 1 0 1 0 1 0 1 0 0 0 1 0 1 0 1 2 3 4 5 6 0 2 3 4 4 6 6 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...