Submission #1195932

#TimeUsernameProblemLanguageResultExecution timeMemory
1195932belgianbotDungeons Game (IOI21_dungeons)C++20
0 / 100
7092 ms12104 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; const int MAX_N = 400001; vector<bool> processed(MAX_N,false), is_processing(MAX_N, false), is_cycle(MAX_N, false); vector<long long> cycle(MAX_N), win(MAX_N); vector<int> s,p,w,l; stack<int> q; int n; void proc(int i) { if (i == n) return; if (is_processing[i]) { while(!q.empty()) { int x = q.top(); q.pop(); is_processing[x] = false; is_cycle[x] = true; if (x == i) break; } return; } if (processed[i]) return; is_processing[i] = true; processed[i] =true; q.push(i); proc(l[i]); } void init(int nn, vector<int> ss, vector<int> pp, vector<int> ww, vector<int> ll) { s = ss; p = pp; w = ww; l = ll; n = nn; for (int i = 0; i < n; i++) { if (!processed[i]) { proc(i); while (!q.empty()) { int x = q.top(); q.pop(); is_processing[x] = false; } } } processed.clear(); processed.resize(MAX_N,false); for (int i = 0; i < n; i++) { if (processed[i] || !is_cycle[i]) continue; int pos = i; long long sz = 0; while (!processed[pos]) { processed[pos] = true; q.push(pos); sz += p[pos]; pos = l[pos]; } while (!q.empty()) { int x = q.top(); q.pop(); cycle[x] = sz; } } win[n] = 0; for (int i = n-1; i >= 0; i--) { win[i] = win[w[i]] + s[i]; } return; } long long simulate(int x, int z) { long long lim = s[x]; long long st = z; int pos = x; if (st >= lim) return st+ win[pos]; while (!is_cycle[pos] && st < lim && pos != n) { st += (long long)(p[pos]); pos = l[pos]; } if (pos == n) return st; if (st >= lim) return st + win[pos]; st += ((lim - st) / cycle[pos]) * cycle[pos]; while (st < lim && pos != n) { st += (long long)(p[pos]); pos = l[pos]; } if (pos == n) return st; return st + win[pos]; }
#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...