結果

問題 No.1211 円環はお断り
ユーザー beetbeet
提出日時 2020-08-30 13:44:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,599 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 206,584 KB
実行使用メモリ 22,688 KB
最終ジャッジ日時 2024-04-27 07:04:13
合計ジャッジ時間 9,422 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
17,888 KB
testcase_01 AC 5 ms
15,716 KB
testcase_02 AC 4 ms
15,716 KB
testcase_03 AC 4 ms
15,712 KB
testcase_04 AC 5 ms
17,764 KB
testcase_05 AC 4 ms
17,756 KB
testcase_06 AC 4 ms
15,848 KB
testcase_07 AC 5 ms
17,764 KB
testcase_08 AC 4 ms
17,756 KB
testcase_09 AC 5 ms
17,896 KB
testcase_10 AC 4 ms
15,724 KB
testcase_11 AC 5 ms
15,860 KB
testcase_12 AC 4 ms
15,844 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 76 ms
18,240 KB
testcase_18 RE -
testcase_19 AC 79 ms
16,604 KB
testcase_20 AC 95 ms
18,400 KB
testcase_21 AC 92 ms
16,860 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 324 ms
19,480 KB
testcase_25 AC 22 ms
18,036 KB
testcase_26 RE -
testcase_27 AC 330 ms
19,840 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 AC 286 ms
19,512 KB
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 AC 5 ms
15,724 KB
testcase_42 AC 5 ms
15,848 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][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