제출 #800467

#제출 시각아이디문제언어결과실행 시간메모리
800467MohamedAliSaidane던전 (IOI21_dungeons)C++17
100 / 100
4032 ms1186504 KiB
#include <bits/stdc++.h> //#include "dungeons.h" using namespace std; typedef vector<int> vi; typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; typedef pair<int,int> pii; #define ff first #define ss second #define pb push_back #define all(x) (x).begin(),(x).end() const int nax = 4e5 + 5; const ll INF = 1e7; const int LG = 24; const int LG2 = 6; const int b = 26; int n; vi S, P, W, L; int sp[nax][LG2][LG]; ll mini[nax][LG2][LG]; ll ps[nax][LG2][LG]; ll POW[LG2]; int cor[(int)(INF + 1)]; void init(int N, vi s, vi p, vi w, vi l) { n = N, S = s, P = p, W= w, L = l; S.pb(0); W.pb(n); POW[0] = 1ll; for(int i =1; i < LG2; i++) POW[i] = (POW[i - 1] * 1ll * b); for(int i = 1; i < b; i++) cor[i] = 0; for(int j = b; j <= INF; j++) cor[j] = cor[j/b] + 1; for(int i = 0; i <= n; i++) { for(int l = 0; l < LG2; l++) { if(S[i] <= POW[l]) { sp[i][l][0] = W[i]; mini[i][l][0] = INF * 1ll * INF; ps[i][l][0] = S[i]; } else { sp[i][l][0] = L[i]; mini[i][l][0] = S[i]; ps[i][l][0] = P[i]; } } } for(int j = 1; j < LG; j++) { for(int i = 0; i <= n; i++) { for(int l = 0; l < LG2; l++) { sp[i][l][j] = sp[sp[i][l][j - 1]][l][j - 1]; mini[i][l][j] = min(mini[i][l][j - 1], mini[sp[i][l][j - 1]][l][j - 1] - ps[i][l][j - 1]); ps[i][l][j] = ps[i][l][j - 1] + ps[sp[i][l][j - 1]][l][j - 1]; } } } } pair<int,ll> check(int i, ll z) { ll delta = 0ll; int l = (z >= INF)? LG2 - 1: cor[z]; //cout << '\t' << i << ' ' << z << ' ' << l << '\n'; for(int j = LG - 1; j >= 0; j--) { bool cond = (mini[i][l][j] - delta <= z) || (sp[i][l][j] == n); if(!(cond)) { delta += ps[i][l][j]; i = sp[i][l][j]; } } if(z + delta < mini[i][l][0]) { delta += ps[i][l][0]; i = sp[i][l][0]; } return {i, delta}; } ll simulate(int x, int Z) { ll z = Z; while(x != n) { // cout << x << ' ' << z << '\n'; pair<int,ll> u = check(x, z); x = u.ff; z += u.ss; z += S[x]; x = W[x]; } return z; } /* int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); /* int n, q; cin >> n >> q; vi s(n), p(n), w(n), l(n); for(int i = 0; i < n; i++) cin >> s[i]; for(int i = 0; i < n; i++) cin >> p[i]; for(int i =0 ;i < n; i++) cin >> w[i]; for(int i = 0;i < n; i++) cin >> l[i]; init(n, s, p, w, l); while(q--) { int x, z; cin >> x >> z; cout << simulate(x, z) << '\n'; } init(3, {2, 6, 9}, {3, 1, 2}, {2, 2, 3}, {1, 0, 1}); cout << simulate(0, 1) << '\n'; cout << simulate(2, 3) << '\n'; } */

컴파일 시 표준 에러 (stderr) 메시지

dungeons.cpp:112:5: warning: "/*" within comment [-Wcomment]
  112 |     /*
      |
#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...