結果

問題 No.1211 円環はお断り
ユーザー LayCurseLayCurse
提出日時 2020-08-30 13:15:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,514 bytes
コンパイル時間 2,545 ms
コンパイル使用メモリ 213,332 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-27 06:47:20
合計ジャッジ時間 6,781 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,756 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

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');
  }
}
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;
  }
  else{
    return 0;
  }
}
int main(){
  int i;
  int ok;
  long long res;
  long long tmp;
  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];
  }
  long long xr20shxY;
  long long WYIGIcGE;
  long long t_ynMSdg;
  xr20shxY = 0;
  WYIGIcGE = 1000000000000000LL;
  while(xr20shxY < WYIGIcGE){
    if((xr20shxY + WYIGIcGE)%2==0){
      t_ynMSdg = (xr20shxY + WYIGIcGE) / 2;
    }
    else{
      t_ynMSdg = (xr20shxY + WYIGIcGE + 1) / 2;
    }
    ok = 0;
    tmp = 0;
    for(i=(0);i<(N);i++){
      tmp += A[i];
      if(tmp >= t_ynMSdg){
        ok |= isok(i, t_ynMSdg);
        ok |= isok(i+1, t_ynMSdg);
      }
    }
    if(ok){
      xr20shxY = t_ynMSdg;
    }
    else{
      WYIGIcGE = t_ynMSdg - 1;
    }
  }
  res =WYIGIcGE;
  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++;
//   }
// 
//   return if[p >= K, 1, 0];
// }
// 
// {
//   int ok;
//   ll res, tmp;
//   rd(N,K,A(N));
//   rep(i,N) A[i+N] = A[i];
// 
//   res = bsearch_max[ll,x,0,1d15][
//     ok = 0;
//     tmp = 0;
//     rep(i,N){
//       tmp += A[i];
//       if(tmp >= x){
//         ok |= isok(i, x);
//         ok |= isok(i+1, x);
//       }
//     }
//   ](ok);
// 
//   wt(res);
// }
0