結果

問題 No.871 かえるのうた
ユーザー otamay6otamay6
提出日時 2019-08-30 23:38:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,799 ms / 2,000 ms
コード長 1,234 bytes
コンパイル時間 1,616 ms
コンパイル使用メモリ 170,716 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-05-01 21:31:40
合計ジャッジ時間 7,299 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 15 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 107 ms
5,376 KB
testcase_15 AC 106 ms
5,376 KB
testcase_16 AC 118 ms
5,376 KB
testcase_17 AC 94 ms
5,376 KB
testcase_18 AC 16 ms
5,376 KB
testcase_19 AC 110 ms
5,376 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 52 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 7 ms
5,376 KB
testcase_27 AC 9 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 33 ms
5,376 KB
testcase_30 AC 81 ms
5,376 KB
testcase_31 AC 4 ms
5,376 KB
testcase_32 AC 88 ms
5,376 KB
testcase_33 AC 83 ms
5,376 KB
testcase_34 AC 19 ms
5,376 KB
testcase_35 AC 48 ms
5,376 KB
testcase_36 AC 68 ms
5,376 KB
testcase_37 AC 49 ms
5,376 KB
testcase_38 AC 110 ms
5,376 KB
testcase_39 AC 136 ms
5,376 KB
testcase_40 AC 1,799 ms
6,940 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 29 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 3 ms
5,376 KB
testcase_46 AC 1 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;

int main(){
    typedef long long ll;
    int N, K; cin >> N >> K;
    vector<ll> X(N), A(N);
    REP(i, N) cin >> X[i];
    REP(i, N) cin >> A[i];
    K--;
    ll l = X[K] - A[K];
    ll r = X[K] + A[K];
    int res = 0;
    int a = -1, b = -1;
    while (true) {
        int ld = lower_bound(All(X), l) - X.begin();
        int rd = lower_bound(All(X), r) - X.begin();
        if (rd==N||r < X[rd]) rd--;
        if (a == -1 && b == -1) {
            for (int i = ld; i <= rd; i++) {
                l = min(l, X[i] - A[i]);
                r = max(r, X[i] + A[i]);
            }
        } else {
            for (int i = ld; i < a; i++) {
                l = min(l, X[i] - A[i]);
                r = max(r, X[i] + A[i]);
            }
            for (int i = b+1; i <= rd; i++) {
                l = min(l, X[i] - A[i]);
                r = max(r, X[i] + A[i]);
            }
        }
        int tmp = res;
        res = rd - ld + 1;
        if (res == tmp) break;
        int a = ld, b = rd;
    }
    cout << res << endl;
    return 0;
}
0