結果

問題 No.871 かえるのうた
ユーザー mmn15277198mmn15277198
提出日時 2021-10-09 13:01:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,428 bytes
コンパイル時間 953 ms
コンパイル使用メモリ 98,456 KB
実行使用メモリ 6,552 KB
最終ジャッジ日時 2023-10-09 21:24:13
合計ジャッジ時間 7,364 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 WA -
testcase_02 AC 2 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,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 3 ms
4,352 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 13 ms
4,352 KB
testcase_13 AC 4 ms
4,352 KB
testcase_14 AC 105 ms
6,420 KB
testcase_15 AC 107 ms
6,540 KB
testcase_16 AC 120 ms
6,480 KB
testcase_17 AC 97 ms
6,540 KB
testcase_18 AC 17 ms
4,348 KB
testcase_19 WA -
testcase_20 AC 9 ms
4,348 KB
testcase_21 AC 42 ms
4,384 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 6 ms
4,348 KB
testcase_27 AC 9 ms
4,352 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 32 ms
5,364 KB
testcase_30 AC 61 ms
5,632 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 52 ms
5,440 KB
testcase_33 AC 82 ms
6,552 KB
testcase_34 AC 19 ms
4,352 KB
testcase_35 AC 50 ms
5,028 KB
testcase_36 AC 69 ms
6,032 KB
testcase_37 AC 42 ms
4,532 KB
testcase_38 AC 98 ms
6,384 KB
testcase_39 AC 87 ms
6,220 KB
testcase_40 AC 28 ms
5,432 KB
testcase_41 AC 1 ms
4,352 KB
testcase_42 AC 28 ms
5,380 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 1 ms
4,352 KB
testcase_47 AC 1 ms
4,348 KB
testcase_48 AC 1 ms
4,348 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--;

  /*
  if (a[k] == 0) {
    cout << 1 << endl;
    return 0;
  }
  */

  long long mn = p[k].first;
  for (int i = k; i < n - 1; i++) {
    if (x[i + 1] <= p[i].second && mn >= p[i + 1].first) {
      mn = p[i].first;
    } else {
      break;
    }
  }

  long long mx = p[k].second;
  for (int i = k; i >= 1; i--) {
    if (x[i - 1] >= p[i].first && mx <= p[i - 1].second) {
      mx = p[i - 1].second;
    } else {
      break;
    }
  }

  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