結果

問題 No.871 かえるのうた
ユーザー mmn15277198mmn15277198
提出日時 2021-10-09 12:30:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,239 bytes
コンパイル時間 1,020 ms
コンパイル使用メモリ 99,112 KB
実行使用メモリ 6,600 KB
最終ジャッジ日時 2023-10-10 21:52:06
合計ジャッジ時間 4,463 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 14 ms
4,352 KB
testcase_13 AC 5 ms
4,352 KB
testcase_14 AC 113 ms
6,600 KB
testcase_15 AC 112 ms
6,436 KB
testcase_16 AC 122 ms
6,544 KB
testcase_17 AC 100 ms
6,216 KB
testcase_18 AC 17 ms
4,352 KB
testcase_19 AC 115 ms
6,472 KB
testcase_20 AC 10 ms
4,352 KB
testcase_21 AC 44 ms
4,356 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 WA -
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 3 ms
4,352 KB
testcase_26 AC 7 ms
4,352 KB
testcase_27 AC 10 ms
4,352 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 36 ms
5,472 KB
testcase_30 AC 64 ms
5,772 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 53 ms
5,392 KB
testcase_33 AC 84 ms
6,600 KB
testcase_34 AC 20 ms
4,352 KB
testcase_35 AC 52 ms
5,396 KB
testcase_36 AC 75 ms
6,048 KB
testcase_37 AC 45 ms
4,360 KB
testcase_38 AC 99 ms
6,428 KB
testcase_39 AC 93 ms
6,124 KB
testcase_40 AC 30 ms
5,488 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 31 ms
5,524 KB
testcase_43 AC 2 ms
4,352 KB
testcase_44 AC 2 ms
4,352 KB
testcase_45 AC 2 ms
4,352 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 1 ms
4,348 KB
testcase_48 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>

using namespace std;

int main() {
  int n , k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<long long> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }

  vector<pair<long long , long long> > p(n);

  for (int i = 0; i < n; i++) {
    p[i]= make_pair(a[i] - x[i] , a[i] + x[i]);
  }

  k--;

  long long mn = 1e18;
  int mn_id = k;
  for (int i = k; i < n; i++) {
    if (mn >= p[i].first) {
      mn = p[i].first;
    }
  }

  long long mx = -1e18;
  for (int i = k; i >= 0; i--) {
    if (mx <= p[i].second) {
      mx = p[i].second;
    }
  }

  vector<int> cnt(n , 0);
  cnt[k] = 1;

  for (int i = k; i < n; i++) {
    if (a[i] <= mx) {
      cnt[i] = cnt[k];
      if (p[i].second >= mx) {
        mx = p[i].second;
      }
    }
  }

  for (int i = k; i >= 0; i--) {
    if (a[i] >= mn) {
      cnt[i] = cnt[k];
      if (p[i].first <= mn) {
        mn = p[i].first;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += cnt[i] > 0;
  }
  cout << ans << endl;
  return 0;
}
0