제출 #440118

#제출 시각아이디문제언어결과실행 시간메모리
440118algorithm16던전 (IOI21_dungeons)C++17
11 / 100
207 ms40112 KiB
#include "dungeons.h" #include<iostream> #include<vector> #include<algorithm> using namespace std; typedef long long int llint; vector <int> s1,p1,w1,l1; int nxtl[50005][25],nxtw[50005][25],sum[50005][25],sumw[50005][25]; 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; s1=s; p1=p; w1=w; l1=l; 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<20;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<20;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=1e7; 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; } x=get(x,lo).first; llint ret=get(x,lo).second; for(int i=0;i<20;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...