結果

問題 No.1597 Matrix Sort
ユーザー ShibuyapShibuyap
提出日時 2021-07-09 22:16:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 1,500 ms
コード長 1,218 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 198,540 KB
実行使用メモリ 42,988 KB
最終ジャッジ日時 2023-09-14 09:30:01
合計ジャッジ時間 6,372 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
42,284 KB
testcase_01 AC 49 ms
42,396 KB
testcase_02 AC 48 ms
42,400 KB
testcase_03 AC 130 ms
42,868 KB
testcase_04 AC 136 ms
42,800 KB
testcase_05 AC 138 ms
42,784 KB
testcase_06 AC 136 ms
42,788 KB
testcase_07 AC 125 ms
42,668 KB
testcase_08 AC 143 ms
42,664 KB
testcase_09 AC 141 ms
42,676 KB
testcase_10 AC 103 ms
42,676 KB
testcase_11 AC 115 ms
42,860 KB
testcase_12 AC 98 ms
42,724 KB
testcase_13 AC 119 ms
42,668 KB
testcase_14 AC 133 ms
42,848 KB
testcase_15 AC 100 ms
42,724 KB
testcase_16 AC 113 ms
42,676 KB
testcase_17 AC 103 ms
42,984 KB
testcase_18 AC 130 ms
42,788 KB
testcase_19 AC 117 ms
42,804 KB
testcase_20 AC 96 ms
42,784 KB
testcase_21 AC 93 ms
42,780 KB
testcase_22 AC 105 ms
42,784 KB
testcase_23 AC 104 ms
42,988 KB
testcase_24 AC 77 ms
42,976 KB
testcase_25 AC 75 ms
42,844 KB
testcase_26 AC 48 ms
42,276 KB
testcase_27 AC 49 ms
42,400 KB
testcase_28 AC 49 ms
42,440 KB
testcase_29 AC 30 ms
42,396 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