結果

問題 No.871 かえるのうた
ユーザー suika_psuika_p
提出日時 2019-08-30 23:07:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,371 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 170,436 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-01 20:22:09
合計ジャッジ時間 6,574 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
typedef long long ll;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll p)
{
    if (p == 0)
        return 1;
    if (!(p % 2))
    {
        ll halfP = p / 2;
        ll half = modpow(a, halfP);
        return half * half % mod;
    }
    else
    {
        return a * modpow(a, p - 1) % mod;
    }
}

ll comb(int a, int b)
{
    if (b > a - b)
        return comb(a, a - b);
    ll ansMul = 1;
    ll ansDiv = 1;
    for (int i = 0; i < b; i++)
    {
        ansMul *= a - i;
        ansDiv *= i + 1;
        ansMul %= mod;
        ansDiv %= mod;
    }
    ll ans = ansMul * modpow(ansDiv, mod - 2) % mod;
    return ans;
}

/*
int num = 200010;
vector<ll> fact(num), ifact(num);
fact[0] = 1;
fact[1] = 1;
for (int i = 2; i < num; i++) {
    fact[i] = fact[i-1] * i;
    fact[i] %= mod;
}
for (int i = 0; i < num; i++) {
    ifact[i] = modpow(ifact[i], mod-2);
    ifact[i] %= mod;
}
*/

int main() {
    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 (r != X[rd]) rd--;
        for (int i = ld; i <= a; i++) {
            if (a <= i && i <= b) continue;
            l = min(l, X[i] - A[i]);
            r = max(r, X[i] + A[i]);
        }
        for (int i = b; i <= rd; i++)
        {
            if (a <= i && i <= b)
                continue;
            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