結果

問題 No.871 かえるのうた
ユーザー LayCurseLayCurse
提出日時 2019-08-30 21:23:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,444 bytes
コンパイル時間 2,540 ms
コンパイル使用メモリ 212,416 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 16:34:34
合計ジャッジ時間 5,371 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 10 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 4 ms
5,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 3 ms
5,376 KB
testcase_35 WA -
testcase_36 AC 8 ms
5,376 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 2 ms
5,376 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 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]);
    }
    if(b+1 < N && mx >= X[b+1]){
      b++;
      chmin(mn, X[b] - A[b]);
      chmax(mx, X[b] + A[b]);
    }
    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];
//     }
//     if(b+1 < N && mx >= X[b+1]){
//       b++;
//       mn <?= X[b] - A[b];
//       mx >?= X[b] + A[b];
//     }
//     if(!fg) break;
//   }
//   wt(b-a+1);
// }
0