結果

問題 No.1597 Matrix Sort
ユーザー firiexpfiriexp
提出日時 2021-07-09 21:58:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 345 ms / 1,500 ms
コード長 1,098 bytes
コンパイル時間 972 ms
コンパイル使用メモリ 105,712 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 08:58:29
合計ジャッジ時間 7,620 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 329 ms
4,380 KB
testcase_04 AC 343 ms
4,376 KB
testcase_05 AC 345 ms
4,380 KB
testcase_06 AC 329 ms
4,376 KB
testcase_07 AC 342 ms
4,376 KB
testcase_08 AC 271 ms
4,376 KB
testcase_09 AC 281 ms
4,380 KB
testcase_10 AC 188 ms
4,380 KB
testcase_11 AC 153 ms
4,376 KB
testcase_12 AC 147 ms
4,376 KB
testcase_13 AC 265 ms
4,380 KB
testcase_14 AC 298 ms
4,376 KB
testcase_15 AC 116 ms
4,380 KB
testcase_16 AC 178 ms
4,384 KB
testcase_17 AC 199 ms
4,380 KB
testcase_18 AC 321 ms
4,380 KB
testcase_19 AC 232 ms
4,376 KB
testcase_20 AC 197 ms
4,384 KB
testcase_21 AC 186 ms
4,376 KB
testcase_22 AC 192 ms
4,376 KB
testcase_23 AC 179 ms
4,380 KB
testcase_24 AC 28 ms
4,376 KB
testcase_25 AC 25 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    ll n, k, p;
    cin >> n >> k >> p;
    vector<int> A(n), B(n);
    for (auto &&i : A) scanf("%d", &i);
    for (auto &&i : B) scanf("%d", &i);
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    int ng = -1, ok = p-1;
    auto f = [&](int x) -> ll {
        ll cnt = 0;
        for (int i = 0; i < n; ++i) {
            cnt += upper_bound(B.begin(),B.end(), x-A[i])-lower_bound(B.begin(),B.end(), -A[i]);
            cnt += upper_bound(B.begin(),B.end(), x+p-A[i])-lower_bound(B.begin(),B.end(), p-A[i]);
        }
        return cnt;
    };
    while(ok-ng > 1){
        int mid = (ok+ng)/2;
        if(f(mid) >= k) ok = mid;
        else ng = mid;
    }
    cout << ok << "\n";
    return 0;
}
0