結果
問題 | No.1211 円環はお断り |
ユーザー |
![]() |
提出日時 | 2020-08-30 15:15:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,416 bytes |
コンパイル時間 | 1,175 ms |
コンパイル使用メモリ | 102,612 KB |
実行使用メモリ | 54,836 KB |
最終ジャッジ日時 | 2024-11-15 08:48:33 |
合計ジャッジ時間 | 56,586 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 26 TLE * 15 |
ソースコード
#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=1e16; bool judge(ll lim){ int M=A.size(); vector<vector<int>> to(M,vector<int> (20,M)); vector<ll> sum={0}; rep(i,M){ ll val=A[i]+sum[i]; sum.push_back(val); } for(int i=0;i<M;i++){ int z=lower_bound(all(sum),sum[i]+lim)-sum.begin(); to[i][0]=z; } 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;i++){ int now=i; for(int k=0;k<20;k++){ if(K&(1<<k)) now=to[now][k]; if(now==M) 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); ll ok=1,ng=INF; while(abs(ok-ng)>1){ ll mid=(ok+ng)/2; if(judge(mid)) ok=mid; else ng=mid; } cout<<ok<<endl; return 0; }