結果

問題 No.1597 Matrix Sort
ユーザー merom686merom686
提出日時 2021-07-09 22:46:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 1,500 ms
コード長 1,190 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 204,324 KB
実行使用メモリ 43,096 KB
最終ジャッジ日時 2023-09-14 10:25:20
合計ジャッジ時間 5,445 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 110 ms
43,048 KB
testcase_04 AC 110 ms
42,956 KB
testcase_05 AC 108 ms
42,940 KB
testcase_06 AC 108 ms
42,980 KB
testcase_07 AC 102 ms
43,096 KB
testcase_08 AC 108 ms
42,880 KB
testcase_09 AC 93 ms
42,936 KB
testcase_10 AC 60 ms
42,952 KB
testcase_11 AC 53 ms
43,044 KB
testcase_12 AC 32 ms
4,384 KB
testcase_13 AC 49 ms
7,724 KB
testcase_14 AC 107 ms
43,000 KB
testcase_15 AC 34 ms
4,380 KB
testcase_16 AC 49 ms
7,768 KB
testcase_17 AC 77 ms
43,056 KB
testcase_18 AC 102 ms
42,936 KB
testcase_19 AC 87 ms
42,960 KB
testcase_20 AC 71 ms
43,040 KB
testcase_21 AC 67 ms
42,952 KB
testcase_22 AC 64 ms
43,008 KB
testcase_23 AC 61 ms
42,996 KB
testcase_24 AC 17 ms
4,380 KB
testcase_25 AC 15 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 22 ms
42,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <class T, class F>
T LowerBound(T i0, T i1, F f) {
    while (i0 < i1) {
        T i = i0 + (i1 - i0) / 2;
        if (f(i)) i1 = i; else i0 = i + 1;
    }
    return i0;
}

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

    int n, p;
    ll k;
    cin >> n >> k >> p;

    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    sort(b.begin(), b.end());

    vector<int> q(p + 1);
    int i = 0;
    for (int j = 0; j <= p; j++) {
        while (i < n && b[i] < j) i++;
        q[j] = i;
    }

    auto c = LowerBound<int>(0, p, [&](auto c) {
        ll l = 0;
        for (const auto &a1 : a) {
            int m = q[p - a1];
            int i0 = c - a1 + 1;
            i0 = clamp(i0, 0, p);
            l += q[i0] - 0;
            int i1 = c + p - a1 + 1;
            i1 = clamp(i1, 0, p);
            l += q[i1] - m;
        }
        //cout << c << ' ' << l << endl;
        return l >= k; // c以下の数がk個以上になった初めての数
    });
    cout << c << endl;

    return 0;
}
0