제출 #440130

#제출 시각아이디문제언어결과실행 시간메모리
440130algorithm16던전 (IOI21_dungeons)C++17
11 / 100
224 ms58368 KiB
#include "dungeons.h" #include<iostream> #include<vector> #include<algorithm> using namespace std; typedef long long int llint; vector <llint> s1,p1,w1,l1; llint nxtl[50005][35],nxtw[50005][35],sum[50005][35],sumw[50005][35]; llint n1,b1=1; void init(int n,std::vector<int> s,std::vector<int> p,std::vector<int> w,std::vector<int> l) { n1=n; for(int i=0;i<n;i++) { s1.push_back(s[i]); p1.push_back(p[i]); w1.push_back(w[i]); l1.push_back(l[i]); } nxtl[n][0]=n; nxtw[n][0]=n; for(int i=0;i<n;i++) { nxtl[i][0]=l[i]; nxtw[i][0]=w[i]; sum[i][0]=p[i]; sumw[i][0]=s[i]; if(i<n-1 && s[i]!=s[i+1]) b1=0; } for(int i=1;i<30;i++) { for(int j=0;j<=n;j++) { nxtl[j][i]=nxtl[nxtl[j][i-1]][i-1]; nxtw[j][i]=nxtw[nxtw[j][i-1]][i-1]; sum[j][i]=sum[j][i-1]+sum[nxtl[j][i-1]][i-1]; sumw[j][i]=sumw[j][i-1]+sumw[nxtw[j][i-1]][i-1]; } } return; } pair <int,llint> get(int x,int v) { llint ret=0; for(int i=0;i<30;i++) { if(v & (1 << i)) { ret+=sum[x][i]; x=nxtl[x][i]; } } return make_pair(x,ret); } long long simulate(int x, int z) { if(b1) { llint lo=0,hi=1e9; while(lo<hi) { llint mid=(lo+hi)/2; //cout << lo << " " << hi << " " << mid << " " << get(x,mid).first << " " << get(x,mid).second << "\n"; if(z+get(x,mid).second>=s1[get(x,mid).first]) hi=mid; else lo=mid+1; } llint ret=get(x,lo).second; x=get(x,lo).first; //cout << ret << "\n"; for(int i=0;i<30;i++) { if((n1-x) & (1 << i)) { ret+=sumw[x][i]; x=nxtw[x][i]; } } return z+ret; } llint ret=z; while(x!=n1) { if(ret<s1[x]) { ret+=p1[x]; x=l1[x]; } else { ret+=s1[x]; x=w1[x]; } } return ret; }
#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...