結果

問題 No.871 かえるのうた
ユーザー risujirohrisujiroh
提出日時 2019-08-30 22:02:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,054 bytes
コンパイル時間 1,887 ms
コンパイル使用メモリ 173,916 KB
実行使用メモリ 23,012 KB
最終ジャッジ日時 2023-08-20 09:18:41
合計ジャッジ時間 5,074 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 15 ms
5,672 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 71 ms
15,500 KB
testcase_15 AC 72 ms
15,516 KB
testcase_16 AC 149 ms
23,012 KB
testcase_17 AC 63 ms
14,824 KB
testcase_18 AC 13 ms
5,588 KB
testcase_19 AC 80 ms
15,832 KB
testcase_20 AC 8 ms
4,544 KB
testcase_21 AC 32 ms
8,028 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 11 ms
4,864 KB
testcase_27 AC 13 ms
5,064 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 35 ms
11,140 KB
testcase_30 AC 76 ms
15,624 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 55 ms
12,276 KB
testcase_33 AC 74 ms
16,444 KB
testcase_34 AC 18 ms
6,388 KB
testcase_35 AC 44 ms
10,804 KB
testcase_36 AC 52 ms
13,400 KB
testcase_37 AC 47 ms
10,140 KB
testcase_38 AC 110 ms
19,516 KB
testcase_39 AC 82 ms
16,624 KB
testcase_40 AC 39 ms
13,264 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 40 ms
14,048 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k, --k;
  V<lint> x(n); for (auto&& e : x) cin >> e;
  V<lint> a(n); for (auto&& e : a) cin >> e;
  VV<> g(2 * n);
  for (int i = 0; i < n; ++i) {
    int l = lower_bound(begin(x), end(x), x[i] - a[i]) - begin(x);
    int r = upper_bound(begin(x), end(x), x[i] + a[i]) - begin(x);
    l += n, r += n;
    while (l < r) {
      if (l & 1) {
        g[n + i].push_back(l++);
      }
      if (r & 1) {
        g[n + i].push_back(--r);
      }
      l >>= 1, r >>= 1;
    }
  }
  for (int i = 1; i < n; ++i) {
    g[i].push_back(2 * i);
    g[i].push_back(2 * i + 1);
  }
  int res = 0;
  bitset<200000> vis;
  auto dfs = [&](const auto& dfs, int v) -> void {
    vis[v] = true;
    res += v >= n;
    for (int w : g[v]) if (!vis[w]) {
      dfs(dfs, w);
    }
  };
  dfs(dfs, n + k);
  cout << res << '\n';
}
0