Submission #615611

#TimeUsernameProblemLanguageResultExecution timeMemory
615611Clan328Dungeons Game (IOI21_dungeons)C++17
0 / 100
7006 ms4712 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; int n; vector<pair<int, int>> G, W; vi dp; int getDP(int i) { if (i == n) { dp[i] = 0; return 0; } dp[i] = W[i].first+getDP(G[i].first); return dp[i]; } void init(int nx, vi s, vi p, vi w, vi l) { n = nx; G = vector<pii>(n); W = vector<pii>(n); for (int i = 0; i < n; i++) { G[i] = {w[i], l[i]}; W[i] = {s[i], p[i]}; } dp = vi(n+1, -1); for (int i = 0; i < n; i++) { if (dp[i] == -1) dp[i] = getDP(i); } } ll simulate(int x, int z) { ll currStrength = z, currCnt = 0; vi cnt(n); vi strength(n); int idx = -1; for (int i = x; i != n; ) { currCnt++; if (cnt[i] != 0) { idx = i; break; } cnt[i] = currCnt; strength[i] = currStrength; if (currStrength >= W[i].first) { currStrength += W[i].first; i = G[i].first; } else { currStrength += W[i].second; i = G[i].second; } } if (idx == -1) return currStrength; int cycleStrength = currStrength-strength[idx]; int remStrength = W[0].first-currStrength; currStrength += (remStrength/cycleStrength)*cycleStrength; for (int i = idx; i != n; ) { if (currStrength >= W[0].first) { idx = i; break; } if (currStrength >= W[i].first) { currStrength += W[i].first; i = G[i].first; } else { currStrength += W[i].second; i = G[i].second; } } return currStrength + dp[idx]; }
#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...