제출 #442838

#제출 시각아이디문제언어결과실행 시간메모리
442838baluteshih던전 (IOI21_dungeons)C++17
25 / 100
252 ms116800 KiB
#include "dungeons.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define X first #define Y second #define ALL(v) v.begin(), v.end() #define pb push_back #define SZ(a) ((int)a.size()) struct node { int to; ll sum; node operator+(const node &a) const { return node{a.to, sum + a.sum}; } }; const int K = 7; int N, lg = __lg(10000000); vector<int> S, P, W, L; vector<int> val; vector<node> dp[K][30]; void init(int n, vector<int> s, vector<int> p, vector<int> w, vector<int> l) { N = n, S = s, P = p, W = w, L = l; for (int i : S) val.pb(i); val.pb(0); sort(ALL(val)), val.resize(unique(ALL(val)) - val.begin()); if (SZ(val) >= K) return; for (int i = 0; i < SZ(val); ++i) { dp[i][0].resize(N + 1); dp[i][0][N] = node{N, 0LL}; for (int j = 0; j < N; ++j) if (val[i] >= S[j]) dp[i][0][j] = node{W[j], (ll)S[j]}; else dp[i][0][j] = node{L[j], (ll)P[j]}; for (int j = 1; j <= lg; ++j) { dp[i][j].resize(N + 1); for (int k = 0; k <= N; ++k) dp[i][j][k] = dp[i][j - 1][k] + dp[i][j - 1][dp[i][j - 1][k].to]; } } return; } long long simulate(int x, int z) { if (SZ(val) >= K) return 0; int p; ll nw = z; for (p = 0; p < SZ(val);) { while (p + 1 < SZ(val) && nw >= val[p + 1]) ++p; if (p == SZ(val) - 1 || (dp[p][lg][x].to == N && nw + dp[p][lg][x].sum < val[p + 1])) break; for (int i = lg; i >= 0; --i) if (nw + dp[p][i][x].sum < val[p + 1]) { nw += dp[p][i][x].sum; x = dp[p][i][x].to; } nw += dp[p][0][x].sum; x = dp[p][0][x].to; } for (int i = lg; i >= 0; --i) if (dp[p][i][x].to != N) { nw += dp[p][i][x].sum; x = dp[p][i][x].to; } nw += dp[p][0][x].sum; return nw; }
#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...