結果

問題 No.1597 Matrix Sort
ユーザー milanis48663220milanis48663220
提出日時 2021-07-09 22:06:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 358 ms / 1,500 ms
コード長 1,729 bytes
コンパイル時間 2,378 ms
コンパイル使用メモリ 150,716 KB
実行使用メモリ 4,916 KB
最終ジャッジ日時 2023-09-14 09:11:16
合計ジャッジ時間 8,461 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 47 ms
4,608 KB
testcase_04 AC 280 ms
4,916 KB
testcase_05 AC 341 ms
4,600 KB
testcase_06 AC 336 ms
4,648 KB
testcase_07 AC 358 ms
4,672 KB
testcase_08 AC 218 ms
4,664 KB
testcase_09 AC 288 ms
4,740 KB
testcase_10 AC 199 ms
4,712 KB
testcase_11 AC 128 ms
4,604 KB
testcase_12 AC 117 ms
4,604 KB
testcase_13 AC 225 ms
4,732 KB
testcase_14 AC 269 ms
4,876 KB
testcase_15 AC 102 ms
4,736 KB
testcase_16 AC 162 ms
4,736 KB
testcase_17 AC 185 ms
4,720 KB
testcase_18 AC 283 ms
4,708 KB
testcase_19 AC 206 ms
4,616 KB
testcase_20 AC 172 ms
4,620 KB
testcase_21 AC 171 ms
4,724 KB
testcase_22 AC 176 ms
4,708 KB
testcase_23 AC 190 ms
4,604 KB
testcase_24 AC 25 ms
4,656 KB
testcase_25 AC 24 ms
4,776 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/convolution>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll n, k, p; cin >> n >> k >> p;
    vector<ll> 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(a.begin(), a.end());
    sort(b.begin(), b.end());
    auto sect_elements = [&](int l, int r)->int{
        if(r < l) return 0;
        if(r < 0) return 0;
        chmax(l, 0);
        int ans = upper_bound(b.begin(), b.end(), r)-lower_bound(b.begin(), b.end(), l);
        // cout << l << ',' << r << ' ' << ans << endl;
        return ans;
    };
    auto calc = [&](int c){
        ll ans = 0;
        for(int i = 0; i < n; i++){
            ans += sect_elements(-a[i], c-a[i]);
            ans += sect_elements(p-a[i], p+c-a[i]);
        }
        return ans;
    };
    if(calc(0) >= k){
        cout << 0 << endl;
        return 0;
    }
    int l = 0, r = p-1;
    while(r-l > 1){
        int c = (l+r)/2;
        if(calc(c) < k) l = c;
        else r = c;
    }
    cout << r << endl;
}
0