Submission #1057842

#TimeUsernameProblemLanguageResultExecution timeMemory
1057842shjeongDungeons Game (IOI21_dungeons)C++17
100 / 100
1818 ms1650796 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; typedef pair<ll,ll> pi; #define all(x) x.begin(),x.end() #define rll(x) x.rbegin(),x.rend() int table[351][400001], mx[351][400001]; //[*][*][i]: 2^(i+1)보다 작은 경우를 나타내는 sparse table, mx는 이름만 max고 min int sum[351][400001]; vector<int> s,p,w,l; int n; ll ed[400001]; int idx[26][26]; void init(int N, std::vector<int> S, std::vector<int> P, std::vector<int> W, std::vector<int> L) { int cnt = 0; for(int i = 0 ; i < 26 ; i++){ for(int j = 0 ; j <= i ; j++)idx[j][i] = cnt++; } s=S,p=P,w=W,l=L; n=N; for(int i = n-1 ; i >= 0 ; i--)ed[i] = ed[w[i]]+s[i]; memset(table,-1,sizeof(table)); fill(&mx[0][0], &mx[351][400001], 1e9); for(int i = 0 ; i < 26 ; i++){ for(int j = 0 ; j < n ; j++){ table[idx[0][i]][j] = (s[j] <= (1<<i) ? w[j] : l[j]); sum[idx[0][i]][j] = (s[j] <= (1<<i) ? s[j] : p[j]); if((1<<i) <= s[j] and s[j] < (1<<i+1)){ mx[idx[0][i]][j] = s[j]; } } } for(int k = 0 ; k < 26 ; k++){ for(int j = 1 ; j <= k ; j++){ for(int i = 0 ; i < n ; i++){ if(table[idx[j-1][k]][i]<0 or table[idx[j-1][k]][table[idx[j-1][k]][i]]<0)continue; table[idx[j][k]][i] = table[idx[j-1][k]][table[idx[j-1][k]][i]]; mx[idx[j][k]][i] = min(mx[idx[j-1][k]][i],mx[idx[j-1][k]][table[idx[j-1][k]][i]]-sum[idx[j-1][k]][i]); if(mx[idx[j][k]][i]<0)mx[idx[j][k]][i]=0; sum[idx[j][k]][i] = sum[idx[j-1][k]][i] + sum[idx[j-1][k]][table[idx[j-1][k]][i]]; if(sum[idx[j][k]][i] > 1e9)sum[idx[j][k]][i] = 1e9; } } } return; } long long simulate(int x, int z) { ll pw = z; for(int i = 0 ; i < 24 ; i++){ for(int j = i ; j >= 0 ; j--){ if(table[idx[j][i]][x]>=0 and pw < min((1<<i+1)-sum[idx[j][i]][x],mx[idx[j][i]][x]))pw += sum[idx[j][i]][x], x = table[idx[j][i]][x]; } if(x==n)break; if(pw < s[x])pw += p[x], x = l[x]; else pw += s[x], x = w[x]; } return pw + ed[x]; }

Compilation message (stderr)

dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:27:47: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   27 |             if((1<<i) <= s[j] and s[j] < (1<<i+1)){
      |                                              ~^~
dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:51:57: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   51 |             if(table[idx[j][i]][x]>=0 and pw < min((1<<i+1)-sum[idx[j][i]][x],mx[idx[j][i]][x]))pw += sum[idx[j][i]][x], x = table[idx[j][i]][x];
      |                                                        ~^~
#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...