結果
問題 | No.1211 円環はお断り |
ユーザー |
![]() |
提出日時 | 2024-09-07 22:39:28 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,593 bytes |
コンパイル時間 | 2,362 ms |
コンパイル使用メモリ | 202,832 KB |
実行使用メモリ | 39,064 KB |
最終ジャッジ日時 | 2024-09-07 22:40:15 |
合計ジャッジ時間 | 44,512 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 31 TLE * 10 |
ソースコード
#include<bits/stdc++.h> #define int long long using namespace std; #define fi first #define sc second #define pii pair<int,int> #define pb push_back const int maxn=2e5+10; int n,k,a[maxn],s[maxn],nxt[maxn][20],f[maxn]; bool chk(int x){ for(int i=1;i<=n*2;i++){ nxt[i][0]=lower_bound(s+1,s+n*2+1,s[i]+x)-s; } for(int i=0;i<=19;i++) nxt[n*2+1][i]=n*2+1; for(int i=1;i<=19;i++){ for(int j=1;j<=n*2;j++) nxt[j][i]=nxt[nxt[j][i-1]][i-1]; } for(int i=1;i<=n;i++){ nxt[n*2][0]=n*2; int now=i; for(int j=0;j<=19;j++){ if(k&(1<<j)) now=nxt[now][j]; } if(now-i<=n) return 1; } return 0; } void solve(){ cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i],a[i+n]=a[i]; for(int i=1;i<=n*2;i++) s[i]=s[i-1]+a[i]; int l=0,r=1e15,mid=0; while(l<=r) mid=(l+r)>>1,(chk(mid)?l=mid+1:r=mid-1); l--,cout<<l<<" "; for(int i=1;i<=n*2;i++){ nxt[i][0]=lower_bound(s+1,s+n*2+1,s[i]+l)-s; } for(int i=0;i<=19;i++) nxt[n*2+1][i]=n*2+1; for(int i=1;i<=19;i++){ for(int j=1;j<=n*2;j++) nxt[j][i]=nxt[nxt[j][i-1]][i-1]; } int res=0; for(int i=1;i<=n;i++){ nxt[n*2][0]=n*2; int now=i; for(int j=0;j<=19;j++){ if(k&(1<<j)) now=nxt[now][j]; } res+=(now-i>n); } // cout<<res<<endl; } signed main(){ ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int t=1; // cin>>t; while(t--) solve(); return 0; } /* Samples input: output: THINGS TODO: ??freopen??????? ???? ???????????? */