結果

問題 No.1211 円環はお断り
ユーザー snow39snow39
提出日時 2020-08-30 15:23:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,397 bytes
コンパイル時間 980 ms
コンパイル使用メモリ 101,692 KB
実行使用メモリ 30,268 KB
最終ジャッジ日時 2024-04-27 08:13:20
合計ジャッジ時間 12,462 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1,269 ms
16,968 KB
testcase_14 AC 1,679 ms
21,652 KB
testcase_15 AC 1,723 ms
21,248 KB
testcase_16 TLE -
testcase_17 AC 178 ms
6,940 KB
testcase_18 AC 1,425 ms
19,080 KB
testcase_19 AC 181 ms
6,944 KB
testcase_20 AC 245 ms
6,944 KB
testcase_21 AC 236 ms
6,944 KB
testcase_22 AC 1,250 ms
17,600 KB
testcase_23 AC 1,597 ms
20,048 KB
testcase_24 AC 820 ms
12,828 KB
testcase_25 AC 34 ms
6,944 KB
testcase_26 AC 1,878 ms
22,616 KB
testcase_27 AC 843 ms
12,872 KB
testcase_28 AC 1,960 ms
23,288 KB
testcase_29 AC 1,501 ms
19,076 KB
testcase_30 TLE -
testcase_31 AC 706 ms
11,736 KB
testcase_32 TLE -
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

bool judge(ll lim){
  int M=A.size();
  vector<vector<int>> to(M,vector<int> (20,M));
  vector<ll> sum(M+1,0);
  rep(i,M) sum[i+1]=sum[i]+A[i];

  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);

  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;
}
0