結果

問題 No.1597 Matrix Sort
ユーザー ShibuyapShibuyap
提出日時 2021-07-09 22:16:06
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 133 ms / 1,500 ms
コード長 1,218 bytes
コンパイル時間 1,707 ms
使用メモリ 42,968 KB
最終ジャッジ日時 2023-02-02 00:04:19
合計ジャッジ時間 5,941 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 32 ms
42,428 KB
testcase_01 AC 31 ms
42,500 KB
testcase_02 AC 31 ms
42,428 KB
testcase_03 AC 127 ms
42,820 KB
testcase_04 AC 132 ms
42,892 KB
testcase_05 AC 130 ms
42,964 KB
testcase_06 AC 128 ms
42,820 KB
testcase_07 AC 125 ms
42,892 KB
testcase_08 AC 110 ms
42,816 KB
testcase_09 AC 111 ms
42,964 KB
testcase_10 AC 84 ms
42,820 KB
testcase_11 AC 96 ms
42,816 KB
testcase_12 AC 79 ms
42,884 KB
testcase_13 AC 102 ms
42,968 KB
testcase_14 AC 133 ms
42,920 KB
testcase_15 AC 81 ms
42,816 KB
testcase_16 AC 97 ms
42,864 KB
testcase_17 AC 110 ms
42,940 KB
testcase_18 AC 125 ms
42,940 KB
testcase_19 AC 109 ms
42,884 KB
testcase_20 AC 106 ms
42,884 KB
testcase_21 AC 104 ms
42,924 KB
testcase_22 AC 102 ms
42,884 KB
testcase_23 AC 88 ms
42,820 KB
testcase_24 AC 59 ms
42,888 KB
testcase_25 AC 58 ms
42,888 KB
testcase_26 AC 31 ms
42,424 KB
testcase_27 AC 32 ms
42,584 KB
testcase_28 AC 31 ms
42,496 KB
testcase_29 AC 32 ms
42,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
#define MAX_N 10000005

int bb[MAX_N];

int main() {
    ll n, K, P;
    cin >> n >> K >> P;
    int a[n] = {};
    rep(i, n) cin >> a[i];
    rep(i, n) {
        int b;
        cin >> b;
        bb[b]++;
    }
    srep(i, 1, MAX_N) { bb[i] += bb[i - 1]; }

    int l = 0, r = P;

    while (l + 1 < r) {
        int m  = (l + r) / 2;
        ll cnt = 0;
        // m以上の数を数える
        rep(i, n) {
            if (a[i] < m) {
                int mi = m - a[i];
                int ma = P - 1 - a[i];
                cnt += bb[ma];
                if (mi > 0) cnt -= bb[mi - 1];
            } else {
                int ma = P - 1 - a[i];
                cnt += bb[ma];
                int mi = P - (a[i] - m);
                if (mi < P) { cnt += bb[P - 1] - bb[mi - 1]; }
            }
        }
        // cout << m << ' ' << cnt << endl;
        if (n * n - cnt >= K) r = m;
        else
            l = m;
    }

    cout << l << endl;
    return 0;
}
0