結果

問題 No.871 かえるのうた
ユーザー m-44
提出日時 2019-09-08 10:30:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 993 ms / 2,000 ms
コード長 626 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 167,924 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-11-30 10:56:20
合計ジャッジ時間 5,742 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n, k;
long long x[100000], a[100000];
bool ans[100000];

void solve(int i) {
  if (ans[i]) {
    return;
  }
  ans[i] = true;
  auto it1 = lower_bound(x, x + n, x[i] - a[i]);
  auto it2 = upper_bound(x, x + n, x[i] + a[i]);
  int j = it1 - x;
  --it2;
  int end = it2 - x;
  while (j <= end) {
    solve(j);
    ++j;
  }
}
int main() {
  cin>>n>>k;
  --k;
  for (int i=0; i<n; i++) cin>>x[i];
  for (int i=0; i<n; i++) cin>>a[i];
  for (int i=0; i<n; i++) ans[i] = false;

  solve(k);
  int cnt = 0;
  for (int i=0; i<n; i++) {
    if (ans[i]) ++cnt;
  }
  cout<<cnt<<endl;
}
0