結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 15 ms
4,352 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 112 ms
6,404 KB
testcase_15 AC 113 ms
6,476 KB
testcase_16 AC 121 ms
6,472 KB
testcase_17 AC 100 ms
6,144 KB
testcase_18 AC 18 ms
4,348 KB
testcase_19 AC 115 ms
6,564 KB
testcase_20 AC 10 ms
4,476 KB
testcase_21 AC 43 ms
4,600 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 WA -
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 6 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,388 KB
testcase_30 AC 64 ms
5,604 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 53 ms
5,696 KB
testcase_33 AC 84 ms
6,432 KB
testcase_34 AC 20 ms
4,376 KB
testcase_35 AC 52 ms
5,248 KB
testcase_36 AC 72 ms
5,944 KB
testcase_37 AC 45 ms
4,480 KB
testcase_38 AC 99 ms
6,320 KB
testcase_39 AC 93 ms
6,300 KB
testcase_40 AC 30 ms
5,376 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 30 ms
5,420 KB
testcase_43 AC 2 ms
4,348 KB
testcase_44 AC 1 ms
4,348 KB
testcase_45 AC 3 ms
4,352 KB
testcase_46 AC 2 ms
4,352 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> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

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

  for (int i = 0; i < n; i++) {
    p[i]= make_pair(x[i] - a[i] , x[i] + a[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 (x[i] <= mx) {
      cnt[i] = cnt[k];
      if (p[i].second >= mx) {
        mx = p[i].second;
      }
    }
  }

  for (int i = k; i >= 0; i--) {
    if (x[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