結果

問題 No.1211 円環はお断り
ユーザー snow39snow39
提出日時 2020-08-30 15:29:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 726 ms / 2,000 ms
コード長 1,465 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 97,808 KB
実行使用メモリ 22,676 KB
最終ジャッジ日時 2023-08-15 10:02:51
合計ジャッジ時間 14,837 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 355 ms
12,716 KB
testcase_14 AC 481 ms
17,476 KB
testcase_15 AC 499 ms
17,392 KB
testcase_16 AC 703 ms
22,060 KB
testcase_17 AC 46 ms
4,992 KB
testcase_18 AC 432 ms
15,152 KB
testcase_19 AC 44 ms
4,928 KB
testcase_20 AC 74 ms
5,496 KB
testcase_21 AC 71 ms
5,604 KB
testcase_22 AC 390 ms
14,980 KB
testcase_23 AC 440 ms
15,284 KB
testcase_24 AC 234 ms
10,296 KB
testcase_25 AC 9 ms
4,380 KB
testcase_26 AC 526 ms
17,744 KB
testcase_27 AC 235 ms
10,384 KB
testcase_28 AC 547 ms
17,976 KB
testcase_29 AC 404 ms
15,144 KB
testcase_30 AC 534 ms
17,744 KB
testcase_31 AC 212 ms
10,280 KB
testcase_32 AC 635 ms
21,040 KB
testcase_33 AC 709 ms
22,676 KB
testcase_34 AC 682 ms
21,744 KB
testcase_35 AC 692 ms
21,932 KB
testcase_36 AC 694 ms
21,692 KB
testcase_37 AC 699 ms
21,832 KB
testcase_38 AC 721 ms
21,840 KB
testcase_39 AC 726 ms
21,692 KB
testcase_40 AC 659 ms
21,704 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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