제출 #403932

#제출 시각아이디문제언어결과실행 시간메모리
403932FidiskSolar Storm (NOI20_solarstorm)C++14
100 / 100
607 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define oo 1e15 #define fi first #define se second #define sp(iiii) setprecision(iiii) #define IO ios_base::sync_with_stdio(false); cin.tie(0) #define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa)) #define cntbit(xxxx) __builtin_popcount(xxxx) #define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1) typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<pair<int,int>,int> piii; typedef pair<long long,long long> pll; typedef pair<pair<long long,long long>,long long> plll; typedef pair<pair<long long,long long>,pair<long long,long long>> pllll; typedef pair<pair<long long,long long>,bool> pllb; const ll base=361; const ll mod=998244353; const ld eps=1e-5; const ll maxn=1e6; ll n,s,k,res,pos,sum[19][1000009],pre[1000009],a[1000009],ans; int g[19][1000009],r[1000009],l[1000009],v[1000009],p[1000009],i,j,cur,cnt; vector<int> loc; ll calc(int x,int y) { ll kq=0; if (getbit(y,21)==1) { kq+=sum[18][x]; x=g[18][x]; kq+=sum[18][x]; x=g[18][x]; kq+=sum[18][x]; x=g[18][x]; kq+=sum[18][x]; x=g[18][x]; } if (getbit(y,20)==1) { kq+=sum[18][x]; x=g[18][x]; kq+=sum[18][x]; x=g[18][x]; } for (ll ii=18;ii>=0;ii--) { if (getbit(y,ii+1)==1) { kq+=sum[ii][x]; x=g[ii][x]; } } return kq; } void Trace(ll x,ll y) { if (y==s) { cout<<s<<'\n'; return; } if (x==n+1) { cout<<y<<'\n'; return; } Trace(r[p[x]]+1,y+1); cout<<p[x]<<' '; } int main(){ IO; cin>>n>>s>>k; for (i=1;i<n;i++) { cin>>a[i+1]; a[i+1]+=a[i]; } for (i=1;i<=n;i++) { cin>>v[i]; } for (i=n;i>0;i--) { ans=i; for (j=ans-1;j>0;j/=2) { while (ans-j>0&&a[ans-j]>=a[i]-k) { ans-=j; } } l[i]=ans; p[l[i]]=max(p[l[i]],i); } for (i=1;i<=n;i++) { ans=i; for (j=n;j>0;j/=2) { while (ans+j<=n&&a[ans+j]<=a[i]+k) { ans+=j; } } r[i]=ans; } for (i=1;i<=n;i++) { p[i]=max(p[i-1],p[i]); } for (i=1;i<=n;i++) { pre[i]=pre[i-1]+v[i]; } for (i=1;i<=n;i++) { //cout<<i<<' '<<p[i]<<' '<<r[i]<<' '<<g[0][i]<<'\n'; g[0][i]=r[p[i]]+1; } g[0][n+1]=n+1; sum[0][n+1]=0; for (i=1;i<=n;i++) { sum[0][i]=pre[g[0][i]-1]-pre[i-1]; } for (i=1;i<=18;i++) { for (j=1;j<=n+1;j++) { g[i][j]=g[i-1][g[i-1][j]]; sum[i][j]=sum[i-1][j]+sum[i-1][g[i-1][j]]; } } //return 0; //cout<<k<<'\n'; for (i=1;i<=n;i++) { ans=calc(i,s)-sum[0][i]+pre[r[p[i]]]-pre[l[p[i]]-1]; if (ans>res) { //cout<<ans<<' '<<res<<' '<<i<<' '<<p[i]<<'\n'; res=ans; pos=i; } } //return 0; ans=0; for (i=1;i<=s;i++) { ans+=v[i]; } //cout<<ans<<'\n'; //cout<<res<<'\n'; cur=pos; cnt=0; while (cur!=n+1&&cnt<s) { loc.push_back(p[cur]); cur=r[p[cur]]+1; cnt++; } //Trace(pos,0); cout<<loc.size()<<'\n'; for (i=0;i<loc.size();i++) { cout<<loc[i]<<' '; } cout<<'\n'; return 0; for (i=1;i<=n;i++) { cout<<a[i]<<' '; } cout<<'\n'; for (i=1;i<=n;i++) { cout<<p[i]<<' '; } cout<<'\n'; for (i=1;i<=n;i++) { cout<<l[i]<<' '; } cout<<'\n'; for (i=1;i<=n;i++) { cout<<r[i]<<' '; } cout<<'\n'; for (i=1;i<=n;i++) { cout<<pre[i]<<' '; } cout<<'\n'; for (i=1;i<=n;i++) { cout<<g[0][i]<<' '; } cout<<'\n'; }

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

SolarStorm.cpp: In function 'int main()':
SolarStorm.cpp:149:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  149 |     for (i=0;i<loc.size();i++) {
      |              ~^~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...