結果

問題 No.1597 Matrix Sort
ユーザー JupytorJupytor
提出日時 2021-07-09 23:48:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 354 ms / 1,500 ms
コード長 2,093 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 93,340 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-14 11:15:11
合計ジャッジ時間 7,682 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 338 ms
4,380 KB
testcase_04 AC 354 ms
4,388 KB
testcase_05 AC 341 ms
4,376 KB
testcase_06 AC 330 ms
4,380 KB
testcase_07 AC 335 ms
4,380 KB
testcase_08 AC 291 ms
4,384 KB
testcase_09 AC 296 ms
4,376 KB
testcase_10 AC 189 ms
4,376 KB
testcase_11 AC 182 ms
4,376 KB
testcase_12 AC 156 ms
4,376 KB
testcase_13 AC 274 ms
4,384 KB
testcase_14 AC 306 ms
4,380 KB
testcase_15 AC 126 ms
4,376 KB
testcase_16 AC 184 ms
4,376 KB
testcase_17 AC 212 ms
4,380 KB
testcase_18 AC 329 ms
4,376 KB
testcase_19 AC 242 ms
4,376 KB
testcase_20 AC 207 ms
4,380 KB
testcase_21 AC 194 ms
4,380 KB
testcase_22 AC 198 ms
4,376 KB
testcase_23 AC 185 ms
4,376 KB
testcase_24 AC 45 ms
4,376 KB
testcase_25 AC 43 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#define flush fflush(stdout)
#define endl '\n'
#define all(v) v.begin(), v.end()
#define pf(dans) printf("%.12lf", dans)
#define pfn(dans) pf(dans); cout << endl;
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod1 = (int)1e9 + 7, mod2 = (int)998244353;
const int INF = (int)1e9 + 10;
const ll LINF = (ll)1e18 + 10;
const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1};

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)
#define reprev(i, n) for (i = n - 1; i >= 0; i--)

template <typename T>
T my_abs(T x){
    return (x >= 0)? x : -x;
}

template <typename T>
void chmax(T &a, T b){
    a = max(a, b);
}

template <typename T>
void chmin(T &a, T b){
    a = min(a, b);
}

ll gcd(ll a, ll b){
    if (a > b) return gcd(b, a);
    if (a == 0) return b;
    return gcd(b % a, a);
}

bool incld_bit(ll bit, int i){
    return ((bit>>i) & 1) == 1;
}

// --------------------------------------------------------------------------------

int main(void){
    int i, j;
    int n, p;
    ll k;
    int a[100003], b[100003];
    
    cin >> n >> k >> p;
    rep0(i, n){
        cin >> a[i];
    }
    rep0(i, n){
        cin >> b[i];
    }

    sort(a, a + n);
    sort(b, b + n);

    int l, r, mid;
    int *p1, *p2, *p3, *p4;
    ll s;
    l = -1;
    r = p;
    while (r - l > 1){
        mid = (l + r) / 2;
        s = 0;
        rep0(i, n){
            p1 = b;
            p2 = upper_bound(b, b + n, mid - a[i]);
            p3 = lower_bound(b, b + n, p - a[i]);
            p4 = upper_bound(b, b + n, p + mid - a[i]);
            s += p2 - p1 + p4 - p3;
        }
        if (s >= k){
            r = mid;
        }else{
            l = mid;
        }
    }

    cout << r << endl;

    return 0;
}
0