Submission #566477

#TimeUsernameProblemLanguageResultExecution timeMemory
566477kartel던전 (IOI21_dungeons)C++17
0 / 100
3 ms1748 KiB
#include <bits/stdc++.h> //#include "grader.cpp" #include "dungeons.h" #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-O3") #pragma GCC optimize("-Ofast") using namespace std; typedef long long ll; const int N = 4e5 + 2; const int log256A = 3; const int log2N = 24; int up[N][log256A][log2N]; ll sum[N][log256A][log2N]; ll dp[N][log256A][log2N]; vector <int> s, w; int n; void init(int _n, vector <int> _s, vector <int> p, vector <int> _w, vector <int> l) { n = _n; s = _s; w = _w; for (int k = 0; k < log256A; k++) { ll L = (1 << (8 * k)); ll R = (1 << (8 * (k + 1))); for (int i = 0; i < n; i++) { if (s[i] <= L) { up[i][k][0] = w[i]; sum[i][k][0] = s[i]; dp[i][k][0] = -4e18; } else { if (s[i] < R) { up[i][k][0] = l[i]; sum[i][k][0] = p[i]; dp[i][k][0] = -s[i]; } else { up[i][k][0] = l[i]; sum[i][k][0] = p[i]; dp[i][k][0] = -4e18; } } } for (int st = 1; st < log2N; st++) { for (int i = 0; i < n; i++) { up[i][k][st] = up[up[i][k][st - 1]][k][st - 1]; sum[i][k][st] = sum[i][k][st - 1] + sum[up[i][k][st - 1]][k][st - 1]; dp[i][k][st] = max(dp[i][k][st - 1], dp[up[i][k][st - 1]][k][st - 1] + sum[i][k][st - 1]); } } } } ll simulate(int x, int start) { ll z = start; for (int k = 0; k < log256A && x != n; k++) { ll l = (1 << (8 * k)); ll r = (1 << (8 * (k + 1))); while (x != n && z >= l && z < r) { for (int j = log2N - 1; j >= 0 && x != n; j--) { while (x != n && z + dp[x][k][j] < 0 && z + sum[x][k][j] < r) { z += sum[x][k][j]; x = up[x][k][j]; } } if (x != n) { z += s[x]; x = w[x]; } } } // assert(x == n); return z; } /* 3 2 2 6 9 3 1 2 2 2 3 1 0 1 0 1 2 3 */
#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...