結果
問題 | No.1211 円環はお断り |
ユーザー |
![]() |
提出日時 | 2020-08-30 15:29:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 814 ms / 2,000 ms |
コード長 | 1,465 bytes |
コンパイル時間 | 861 ms |
コンパイル使用メモリ | 97,680 KB |
実行使用メモリ | 22,016 KB |
最終ジャッジ日時 | 2024-11-23 16:20:46 |
合計ジャッジ時間 | 16,133 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 41 |
ソースコード
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template<class T> void chmin(T &a,const T &b){if(a>b) a=b;} template<class T> void chmax(T &a,const T &b){if(a<b) a=b;} int N,K; vector<ll> A; const ll INF=1e15; vector<ll> sum; int to[200020][20]; bool judge(ll lim){ int M=A.size(); rep(i,M) rep(j,20) to[i][j]=M; int pos=0; for(int i=0;i<M;i++){ while(pos<M&&sum[i]+lim>sum[pos]) pos++; to[i][0]=pos; } for(int k=1;k<20;k++) for(int i=0;i<M;i++){ if(to[i][k-1]==M) to[i][k]=M; else to[i][k]=to[to[i][k-1]][k-1]; } for(int i=0;i<=N-K;i++){ int now=i; for(int k=0;k<20;k++){ if(K&(1<<k)) now=to[now][k]; if(now-i>N) break; } if(now-i<=N) return true; } return false; } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin>>N>>K; A.resize(N); rep(i,N) cin>>A[i]; rep(i,N) A.push_back(A[i]); A.push_back(INF); int M=A.size(); sum.resize(M+1,0); rep(i,M) sum[i+1]=sum[i]+A[i]; ll ok=*min_element(all(A)); ll ng=sum[N]+10; while(abs(ok-ng)>1){ ll mid=(ok+ng)/2; if(judge(mid)) ok=mid; else ng=mid; } cout<<ok<<endl; return 0; }