結果

問題 No.1597 Matrix Sort
ユーザー simkarensimkaren
提出日時 2021-11-15 11:28:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 440 ms / 1,500 ms
コード長 1,038 bytes
コンパイル時間 2,082 ms
コンパイル使用メモリ 183,876 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 02:05:10
合計ジャッジ時間 12,524 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 333 ms
4,376 KB
testcase_04 AC 345 ms
4,376 KB
testcase_05 AC 432 ms
4,376 KB
testcase_06 AC 440 ms
4,380 KB
testcase_07 AC 436 ms
4,380 KB
testcase_08 AC 279 ms
4,376 KB
testcase_09 AC 378 ms
4,380 KB
testcase_10 AC 252 ms
4,376 KB
testcase_11 AC 236 ms
4,376 KB
testcase_12 AC 160 ms
4,376 KB
testcase_13 AC 291 ms
4,380 KB
testcase_14 AC 348 ms
4,380 KB
testcase_15 AC 160 ms
4,376 KB
testcase_16 AC 230 ms
4,376 KB
testcase_17 AC 266 ms
4,376 KB
testcase_18 AC 359 ms
4,376 KB
testcase_19 AC 289 ms
4,376 KB
testcase_20 AC 250 ms
4,376 KB
testcase_21 AC 250 ms
4,376 KB
testcase_22 AC 258 ms
4,376 KB
testcase_23 AC 277 ms
4,380 KB
testcase_24 AC 49 ms
4,380 KB
testcase_25 AC 48 ms
4,384 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int N, P;
ll K;
vector<int> A, B;

void input(void){
    cin >> N >> K >> P;
    A.resize(N);
    for (int& ai : A)
        cin >> ai;
    B.resize(N);
    for (int& bi : B)
        cin >> bi;
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
}

int _count_B(int l, int r){
    if (r <= l) return 0;
    auto l_iter = lower_bound(B.begin(), B.end(), l);
    auto r_iter = lower_bound(B.begin(), B.end(), r);
    return (r_iter - l_iter);
}

int count_B(int ai, int v){
    return (_count_B(0, v - ai + 1) + _count_B(P - ai, P + v - ai + 1));
}

ll count_v(int v){
    ll ret = 0;
    for (int ai : A)
        ret += count_B(ai, v);
    return ret;
}

int solve(void){
    int l = -1, r = 2 * P - 2;
    while (r - l > 1){
        int mid = (l + r) / 2;
        if (count_v(mid) < K) l = mid;
        else r = mid;
    }
    return r;
}

int main(void){
    input();
    cout << solve() << endl;
    return 0;
}
0