제출 #1195924

#제출 시각아이디문제언어결과실행 시간메모리
1195924belgianbotDungeons Game (IOI21_dungeons)C++20
0 / 100
2 ms3652 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); 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; } } return; } long long simulate(int x, int z) { long long lim = s[x]; long long st = z; if (st >= lim) return z; int pos = x; while (!is_cycle[pos] && st < lim && pos != n) { st += (long long)(p[pos]); pos = l[pos]; } if (st >= lim || pos == n) return st; //st += ((lim - st) / cycle[pos]) * cycle[pos]; while (st < lim && pos != n) { st += (long long)(p[pos]); pos = l[pos]; } return st; }
#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...