結果

問題 No.1211 円環はお断り
ユーザー LayCurseLayCurse
提出日時 2020-08-30 16:08:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,530 ms / 2,000 ms
コード長 4,071 bytes
コンパイル時間 2,733 ms
コンパイル使用メモリ 209,968 KB
実行使用メモリ 6,092 KB
最終ジャッジ日時 2023-08-15 10:05:19
合計ジャッジ時間 24,514 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1,069 ms
4,668 KB
testcase_14 AC 632 ms
5,136 KB
testcase_15 AC 1,251 ms
5,088 KB
testcase_16 AC 1,413 ms
5,856 KB
testcase_17 AC 79 ms
4,380 KB
testcase_18 AC 1,362 ms
4,848 KB
testcase_19 AC 91 ms
4,380 KB
testcase_20 AC 137 ms
4,380 KB
testcase_21 AC 158 ms
4,380 KB
testcase_22 AC 1,030 ms
4,764 KB
testcase_23 AC 871 ms
4,928 KB
testcase_24 AC 307 ms
4,380 KB
testcase_25 AC 15 ms
4,380 KB
testcase_26 AC 1,530 ms
5,212 KB
testcase_27 AC 277 ms
4,496 KB
testcase_28 AC 1,334 ms
5,224 KB
testcase_29 AC 880 ms
4,968 KB
testcase_30 AC 866 ms
5,444 KB
testcase_31 AC 452 ms
4,448 KB
testcase_32 AC 1,200 ms
5,624 KB
testcase_33 AC 979 ms
5,880 KB
testcase_34 AC 978 ms
5,912 KB
testcase_35 AC 875 ms
5,880 KB
testcase_36 AC 1,084 ms
5,912 KB
testcase_37 AC 983 ms
5,900 KB
testcase_38 AC 14 ms
5,920 KB
testcase_39 AC 14 ms
6,092 KB
testcase_40 AC 22 ms
5,920 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int K;
long long A[200000];
int isok(int s, long long x){
  int i;
  int p = 0;
  long long tmp = 0;
  s %= N;
  for(i=(0);i<(N);i++){
    tmp += A[i+s];
    if(tmp >= x){
      tmp = 0;
      p++;
    }
    if(p >= K){
      return 1;
    }
  }
  return 0;
}
int main(){
  int i;
  int ok;
  int s = 0;
  long long res = 0;
  long long tmp;
  long long mx;
  rd(N);
  rd(K);
  {
    int Q5VJL1cS;
    for(Q5VJL1cS=(0);Q5VJL1cS<(N);Q5VJL1cS++){
      rd(A[Q5VJL1cS]);
    }
  }
  for(i=(0);i<(N);i++){
    A[i+N] = A[i];
  }
  {
    int xr20shxY;
    long long WYIGIcGE;
    if(N==0){
      WYIGIcGE = 0;
    }
    else{
      WYIGIcGE = A[0];
      for(xr20shxY=(1);xr20shxY<(N);xr20shxY++){
        WYIGIcGE += A[xr20shxY];
      }
    }
    mx =WYIGIcGE/ K;
  }
  long long ao_dF3pO;
  long long tU__gIr_;
  long long a2conNHc;
  ao_dF3pO = 1;
  tU__gIr_ = mx;
  while(ao_dF3pO < tU__gIr_){
    if((ao_dF3pO + tU__gIr_)%2==0){
      a2conNHc = (ao_dF3pO + tU__gIr_) / 2;
    }
    else{
      a2conNHc = (ao_dF3pO + tU__gIr_ + 1) / 2;
    }
    ok = 0;
    tmp = 0;
    for(i=(0);i<(2*N);i++){
      tmp += A[i];
      if(tmp >= a2conNHc){
        tmp = 0;
        s = i;
      }
    }
    ok |= isok(s+1, a2conNHc);
    for(i=(0);i<(300);i++){
      if(!ok){
        ok |= isok(rand()%N, a2conNHc);
      }
    }
    if(ok){
      ao_dF3pO = a2conNHc;
    }
    else{
      tU__gIr_ = a2conNHc - 1;
    }
  }
  chmax(res, tU__gIr_);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200813-1 [beta]

// --- original code ---
// int N, K; ll A[2d5];
// 
// int isok(int s, ll x){
//   int p = 0;
//   ll tmp = 0;
//   s %= N;
// 
//   rep(i,N){
//     tmp += A[i+s];
//     if(tmp >= x) tmp = 0, p++;
//     if(p >= K) return 1;
//   }
// 
//   return 0;
// }
// 
// {
//   int ok, s = 0;
//   ll res = 0, tmp, mx;
//   rd(N,K,A(N));
//   rep(i,N) A[i+N] = A[i];
// 
//   mx = sum(A(N)) / K;
// 
//   res >?= bsearch_max[ll,x,1,mx][
//     ok = 0;
//     tmp = 0;
//     rep(i,2*N){
//       tmp += A[i];
//       if(tmp >= x){
//         tmp = 0;
//         s = i;
//       }
//     }
//     ok |= isok(s+1, x);
//     rep(i,300) if(!ok) ok |= isok(rand()%N, x);
//   ](ok);
// 
//   wt(res);
// }
0