結果

問題 No.871 かえるのうた
コンテスト
ユーザー m-44
提出日時 2019-09-08 10:30:37
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 626 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,130 ms
コンパイル使用メモリ 181,352 KB
実行使用メモリ 9,788 KB
最終ジャッジ日時 2026-10-19 14:22:51
合計ジャッジ時間 11,797 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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