結果

問題 No.1211 円環はお断り
ユーザー beetbeet
提出日時 2020-08-30 13:45:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 898 ms / 2,000 ms
コード長 1,603 bytes
コンパイル時間 2,386 ms
コンパイル使用メモリ 203,864 KB
実行使用メモリ 52,744 KB
最終ジャッジ日時 2023-08-15 09:51:14
合計ジャッジ時間 19,270 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
42,300 KB
testcase_01 AC 8 ms
42,440 KB
testcase_02 AC 8 ms
42,356 KB
testcase_03 AC 9 ms
42,288 KB
testcase_04 AC 8 ms
42,276 KB
testcase_05 AC 8 ms
42,264 KB
testcase_06 AC 8 ms
42,304 KB
testcase_07 AC 8 ms
42,268 KB
testcase_08 AC 9 ms
42,268 KB
testcase_09 AC 8 ms
42,432 KB
testcase_10 AC 9 ms
42,348 KB
testcase_11 AC 8 ms
42,272 KB
testcase_12 AC 8 ms
42,280 KB
testcase_13 AC 419 ms
49,232 KB
testcase_14 AC 568 ms
50,428 KB
testcase_15 AC 558 ms
50,232 KB
testcase_16 AC 854 ms
52,680 KB
testcase_17 AC 72 ms
42,632 KB
testcase_18 AC 516 ms
49,872 KB
testcase_19 AC 74 ms
42,644 KB
testcase_20 AC 89 ms
42,748 KB
testcase_21 AC 88 ms
42,664 KB
testcase_22 AC 454 ms
49,448 KB
testcase_23 AC 539 ms
50,004 KB
testcase_24 AC 293 ms
48,148 KB
testcase_25 AC 24 ms
42,520 KB
testcase_26 AC 616 ms
50,740 KB
testcase_27 AC 299 ms
48,004 KB
testcase_28 AC 625 ms
50,836 KB
testcase_29 AC 501 ms
50,032 KB
testcase_30 AC 667 ms
51,160 KB
testcase_31 AC 258 ms
47,876 KB
testcase_32 AC 779 ms
51,960 KB
testcase_33 AC 885 ms
52,672 KB
testcase_34 AC 881 ms
52,608 KB
testcase_35 AC 859 ms
52,592 KB
testcase_36 AC 855 ms
52,708 KB
testcase_37 AC 880 ms
52,704 KB
testcase_38 AC 874 ms
52,636 KB
testcase_39 AC 898 ms
52,620 KB
testcase_40 AC 668 ms
52,744 KB
testcase_41 AC 8 ms
42,344 KB
testcase_42 AC 9 ms
42,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}


template<typename T, typename ...Ts>
vector<T> fusion(vector<T> bs,Ts... ts){
  auto append=[&](auto vs){for(auto v:vs) bs.emplace_back(v);};
  initializer_list<Int>{(void(append(ts)),0)...};
  return bs;
}

//INSERT ABOVE HERE
const Int LOG = 20;
const Int MAX = 1e5 + 100;
Int nx[LOG][3 * MAX];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n,m;
  cin>>n>>m;
  auto as=read(n);

  auto rs=fusion(as,as);
  vector<Int> sm(2*n+1);
  for(Int i=0;i<2*n;i++) sm[i+1]=sm[i]+rs[i];

  auto check=[&](Int d)->Int{
    for(Int i=0;i<=2*n;i++)
      nx[0][i]=lower_bound(sm.begin(),sm.end(),sm[i]+d)-sm.begin();

    for(Int k=0;k<LOG;k++) nx[k][2*n+1]=2*n+1;

    for(Int k=0;k+1<LOG;k++)
      for(Int i=0;i<=2*n;i++)
        nx[k+1][i]=nx[k][nx[k][i]];

    for(Int i=0;i<n;i++){    nx[0][2*n]=2*n+1;
      Int j=i;
      for(Int k=0;k<LOG;k++)
        if((m>>k)&1) j=nx[k][j];

      // cout<<d<<':'<<m<<':'<<i<<' '<<j<<newl;
      if(j-i<=n) return 1;
    }
    return 0;
  };

  Int L=0,R=1e15;
  // check(L) : true
  // check(R) : false
  while(L+1<R){
    Int M=(L+R)>>1;
    if(check(M)) L=M;
    else R=M;
  }
  cout<<L<<newl;
  return 0;
}
0