結果

問題 No.1597 Matrix Sort
ユーザー milanis48663220milanis48663220
提出日時 2021-07-09 22:06:19
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 385 ms / 1,500 ms
コード長 1,729 bytes
コンパイル時間 2,075 ms
使用メモリ 4,784 KB
最終ジャッジ日時 2023-02-01 23:39:11
合計ジャッジ時間 8,561 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,464 KB
testcase_01 AC 2 ms
3,564 KB
testcase_02 AC 2 ms
3,540 KB
testcase_03 AC 45 ms
4,564 KB
testcase_04 AC 303 ms
4,572 KB
testcase_05 AC 369 ms
4,680 KB
testcase_06 AC 362 ms
4,700 KB
testcase_07 AC 385 ms
4,696 KB
testcase_08 AC 246 ms
4,656 KB
testcase_09 AC 319 ms
4,776 KB
testcase_10 AC 201 ms
4,736 KB
testcase_11 AC 130 ms
4,780 KB
testcase_12 AC 122 ms
4,652 KB
testcase_13 AC 243 ms
4,780 KB
testcase_14 AC 290 ms
4,784 KB
testcase_15 AC 103 ms
4,560 KB
testcase_16 AC 162 ms
4,648 KB
testcase_17 AC 186 ms
4,732 KB
testcase_18 AC 307 ms
4,660 KB
testcase_19 AC 214 ms
4,568 KB
testcase_20 AC 173 ms
4,616 KB
testcase_21 AC 171 ms
4,780 KB
testcase_22 AC 181 ms
4,560 KB
testcase_23 AC 192 ms
4,568 KB
testcase_24 AC 26 ms
4,700 KB
testcase_25 AC 23 ms
4,684 KB
testcase_26 AC 2 ms
3,520 KB
testcase_27 AC 1 ms
3,560 KB
testcase_28 AC 1 ms
3,564 KB
testcase_29 AC 1 ms
3,460 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