結果

問題 No.1597 Matrix Sort
ユーザー aradarad
提出日時 2023-06-03 13:38:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 762 ms / 1,500 ms
コード長 1,804 bytes
コンパイル時間 4,234 ms
コンパイル使用メモリ 263,540 KB
実行使用メモリ 5,524 KB
最終ジャッジ日時 2023-08-28 07:49:05
合計ジャッジ時間 17,903 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 691 ms
5,388 KB
testcase_04 AC 750 ms
5,368 KB
testcase_05 AC 762 ms
5,468 KB
testcase_06 AC 739 ms
5,468 KB
testcase_07 AC 748 ms
5,396 KB
testcase_08 AC 521 ms
5,484 KB
testcase_09 AC 540 ms
5,480 KB
testcase_10 AC 202 ms
5,384 KB
testcase_11 AC 169 ms
5,388 KB
testcase_12 AC 421 ms
5,440 KB
testcase_13 AC 588 ms
5,376 KB
testcase_14 AC 665 ms
5,376 KB
testcase_15 AC 150 ms
5,408 KB
testcase_16 AC 254 ms
5,368 KB
testcase_17 AC 281 ms
5,436 KB
testcase_18 AC 718 ms
5,432 KB
testcase_19 AC 716 ms
5,348 KB
testcase_20 AC 703 ms
5,524 KB
testcase_21 AC 472 ms
5,360 KB
testcase_22 AC 239 ms
5,408 KB
testcase_23 AC 214 ms
5,452 KB
testcase_24 AC 46 ms
5,432 KB
testcase_25 AC 43 ms
5,372 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using P = pair<ll,ll>;
using VP = vector<P>;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define out(x) cout << x << endl
#define dout(x) cout << fixed << setprecision(10) << x << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)(x.size())
#define re0 return 0
#define pcnt __builtin_popcountll
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; }
constexpr int inf = 1e9;
constexpr ll INF = 1e18;
//using mint = modint1000000007;
using mint = modint998244353;
int di[4] = {1,0,-1,0};
int dj[4] = {0,1,0,-1};

int main(){
    ll n,k,p;
    cin >> n >> k >> p;
    VL a(n),b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    sort(all(b));
    b.push_back(INF);
    auto f = [&](ll x){
        ll res = 0;
        rep(i,n){
            auto itr1 = upper_bound(all(b),x-a[i]);
            res += itr1-b.begin();
            auto itr2 = upper_bound(all(b),p-1-a[i]);
            auto itr3 = upper_bound(all(b),p+x-a[i]);
            res += (itr3-b.begin())-(itr2-b.begin());
            //cout << itr1-b.begin() << ' ' << itr2-b.begin() << ' ' << itr3-b.begin() << ' ' << endl;
        }
        return res;
    };
    ll ok = p,ng = -1;
    while(abs(ok-ng) > 1){
        ll mid = (ok+ng)/2;
        //cout << mid << ' ' << f(mid) << endl;
        if(f(mid) >= k) ok = mid;
        else ng = mid; 
    }
    out(ok);
}
0