結果

問題 No.871 かえるのうた
ユーザー outlineoutline
提出日時 2021-01-18 02:44:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,801 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 135,732 KB
実行使用メモリ 4,780 KB
最終ジャッジ日時 2023-08-20 08:44:38
合計ジャッジ時間 4,066 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 36 ms
4,592 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 32 ms
4,552 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 4 ms
4,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 13 ms
4,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 7 ms
4,376 KB
testcase_35 WA -
testcase_36 AC 23 ms
4,416 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 12 ms
4,380 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K;
    cin >> N >> K;
    --K;
    vector<ll> X(N), A(N);
    for(int i = 0; i < N; ++i)  cin >> X[i];
    for(int i = 0; i < N; ++i)  cin >> A[i];

    int i = K - 1, j = K + 1;
    int l = lower_bound(begin(X), end(X), X[K] - A[K]) - begin(X);
    int r = upper_bound(begin(X), end(X), X[K] + A[K] + 1) - begin(X);
    while(l < i && j < r){
        if(l < i){
            chmin<int>(l, lower_bound(begin(X), end(X), X[i] - A[i]) - begin(X));
            chmax<int>(r, upper_bound(begin(X), end(X), X[i] + A[i] + 1) - begin(X));
            --i;
        }
        if(j < r){
            chmin<int>(l, lower_bound(begin(X), end(X), X[j] - A[j]) - begin(X));
            chmax<int>(r, upper_bound(begin(X), end(X), X[j] + A[j] + 1) - begin(X));
            ++j;
        }
    }

    cout << r - l << endl;

    return 0;
}
0