結果

問題 No.871 かえるのうた
ユーザー LayCurseLayCurse
提出日時 2019-08-30 21:24:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 2,506 bytes
コンパイル時間 3,981 ms
コンパイル使用メモリ 209,956 KB
実行使用メモリ 5,020 KB
最終ジャッジ日時 2023-08-20 09:15:51
合計ジャッジ時間 5,032 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 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,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 12 ms
4,956 KB
testcase_15 AC 11 ms
4,912 KB
testcase_16 AC 12 ms
4,908 KB
testcase_17 AC 11 ms
4,704 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 12 ms
4,940 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 5 ms
4,384 KB
testcase_30 AC 7 ms
4,436 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 7 ms
4,380 KB
testcase_33 AC 9 ms
5,020 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 6 ms
4,380 KB
testcase_36 AC 8 ms
4,760 KB
testcase_37 AC 6 ms
4,380 KB
testcase_38 AC 11 ms
4,740 KB
testcase_39 AC 10 ms
4,788 KB
testcase_40 AC 5 ms
4,384 KB
testcase_41 AC 2 ms
4,384 KB
testcase_42 AC 4 ms
4,384 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = 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, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
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 X[100000];
long long A[100000];
int main(){
  int a, b;
  long long mn, mx;
  rd(N);
  rd(K);K += (-1);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
      rd(X[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY;
    for(KL2GvlyY=0;KL2GvlyY<(N);KL2GvlyY++){
      rd(A[KL2GvlyY]);
    }
  }
  a = b = K;
  mn = X[K] - A[K];
  mx = X[K] + A[K];
  for(;;){
    int fg=0;
    if(a-1 >= 0 && mn <= X[a-1]){
      a--;
      chmin(mn, X[a] - A[a]);
      chmax(mx, X[a] + A[a]);
      fg = 1;
    }
    if(b+1 < N && mx >= X[b+1]){
      b++;
      chmin(mn, X[b] - A[b]);
      chmax(mx, X[b] + A[b]);
      fg = 1;
    }
    if(!fg){
      break;
    }
  }
  wt_L(b-a+1);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190830-1

// --- original code ---
// int N, K;
// ll X[1d5], A[1d5];
// {
//   int a, b;
//   ll mn, mx;
//   rd(N,K--,X(N),A(N));
//   a = b = K;
//   mn = X[K] - A[K];
//   mx = X[K] + A[K];
//   for(;;){
//     int fg = 0;
//     if(a-1 >= 0 && mn <= X[a-1]){
//       a--;
//       mn <?= X[a] - A[a];
//       mx >?= X[a] + A[a];
//       fg = 1;
//     }
//     if(b+1 < N && mx >= X[b+1]){
//       b++;
//       mn <?= X[b] - A[b];
//       mx >?= X[b] + A[b];
//       fg = 1;
//     }
//     if(!fg) break;
//   }
//   wt(b-a+1);
// }
0