제출 #852190

#제출 시각아이디문제언어결과실행 시간메모리
852190alex_2008던전 (IOI21_dungeons)C++17
63 / 100
3766 ms2097152 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; const int N = 4e5 + 10; const int M = 10000001; int INF = 1e7; long long INFF = 1e7 + 1; long long INFFF = 100000020000001; long long ZERO = 0; long long dp[N * 24 * 24]; long long NN; vector <long long> ss, pp, ww, ll; long long nxt[N]; int lg2[M]; long long f(long long pos, long long strength, long long mindiff) { return pos * INFFF + strength * INFF + mindiff; } long long pos(int i, int j, int k) { return dp[i * 576 + j * 24 + k] / INFFF; } long long strength(int i, int j, int k) { return (dp[i * 576 + j * 24 + k] / INFF) % INFF; } long long mindiff(int i, int j, int k) { return dp[i * 576 + j * 24 + k] % INFF; } void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) { bool ch = true; lg2[1] = 0; for (int i = 2; i < M; i++) { lg2[i] = lg2[i / 2] + 1; } NN = n; s.push_back(0); p.push_back(0); w.push_back(n); l.push_back(n); for (int i = 0; i <= n; i++) { ss.push_back(s[i]); if (w[i] != l[i]) ch = false; } if (ch) { INF = 2 * n; INFF = 2 * n + 1; INFFF = INFF * INFF; } nxt[n] = 0; for (int i = n - 1; i >= 0; i--) { nxt[i] = s[i] + nxt[w[i]]; } for (int i = 0; i <= n; i++) { pp.push_back(p[i]); } for (int i = 0; i <= n; i++) { ww.push_back(w[i]); } for (int i = 0; i <= n; i++) { ll.push_back(l[i]); } for (int k = 0; k < 24; k++) { for (int i = 0; i <= n; i++) { for (int j = 0; j < 24; j++) { if (k == 0) { int a = ((1 << j) >= s[i]) ? w[i] : l[i]; int b = ((1 << j) >= s[i]) ? s[i] : p[i]; int c = ((1 << j) < s[i]) ? s[i] : INF; dp[i * 576 + j * 24 + k] = f(a, b, c); } else { int v = pos(i, j, k - 1); dp[i * 576 + j * 24 + k] = f(pos(v, j, k - 1), min(INFF - 1, strength(i, j, k - 1) + strength(v, j, k - 1)), max(ZERO, min(mindiff(i, j, k - 1), mindiff(v, j, k - 1) - strength(i, j, k - 1)))); } } } } } long long simulate(int xx, int zz) { long long x = xx, z = zz; while (1) { int v = lg2[z]; if (z >= 10000000) { z += nxt[x]; return z; } for (int k = 23; k >= 0; k--) { if (pos(x, v, k) == NN || mindiff(x, v, k) <= z || (z + strength(x, v, k) >= 10000000) || lg2[z + strength(x, v, k)] > v) continue; z += strength(x, v, k); x = pos(x, v, k); } if (z >= ss[x]) { z += ss[x]; x = ww[x]; } else { z += pp[x]; x = ll[x]; } if (x == NN) return z; } } //int main() { // init(3, { 2, 6, 9 }, { 3, 1, 2 }, { 2, 2, 3 }, { 1, 0, 1 }); // cout << simulate(0, 1) << "\n"; // cout << simulate(2, 3) << "\n"; //}
#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...