結果

問題 No.871 かえるのうた
ユーザー Y17Y17
提出日時 2019-08-30 22:57:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 160,324 KB
実行使用メモリ 15,988 KB
最終ジャッジ日時 2023-08-20 09:21:44
合計ジャッジ時間 5,816 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 21 ms
5,852 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 163 ms
15,876 KB
testcase_15 AC 162 ms
15,816 KB
testcase_16 AC 193 ms
15,988 KB
testcase_17 AC 146 ms
15,152 KB
testcase_18 AC 25 ms
6,084 KB
testcase_19 AC 168 ms
15,904 KB
testcase_20 AC 13 ms
4,476 KB
testcase_21 AC 63 ms
8,056 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 11 ms
4,816 KB
testcase_27 AC 15 ms
5,516 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 66 ms
11,396 KB
testcase_30 AC 115 ms
12,864 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 94 ms
11,660 KB
testcase_33 AC 135 ms
15,948 KB
testcase_34 AC 31 ms
6,912 KB
testcase_35 AC 80 ms
10,980 KB
testcase_36 AC 113 ms
13,692 KB
testcase_37 AC 69 ms
8,484 KB
testcase_38 AC 166 ms
15,064 KB
testcase_39 AC 154 ms
14,588 KB
testcase_40 AC 76 ms
11,968 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 75 ms
12,192 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 3 ms
4,376 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
signed main(){
    int n, k;
    cin >> n >> k;

    int x[100010];
    int a[100010];
    for(int i = 0;i < n;i++) cin >> x[i];
    for(int i = 0;i < n;i++) cin >> a[i];

    map<int, int> mp;
    set<int> st;

    for(int i = 0;i < n;i++){
        mp[x[i]] = i;
        if(i != k-1) st.insert(x[i]);
    }

    int ans = 0;

    queue<int> que;
    que.push(x[k-1]);

    while(!que.empty()){
        int idx = mp[que.front()];
        que.pop();
        ans++;

        int l = x[idx]-a[idx];
        int r = x[idx]+a[idx];

        for(auto itr = st.lower_bound(l);itr != st.end() && *itr <= r;){
            que.push(*itr);
            int tmp = *itr;
            *itr++;
            st.erase(tmp);
        }
    }

    cout << ans << endl;
    return 0;
}
0