結果

問題 No.1597 Matrix Sort
ユーザー HaaHaa
提出日時 2021-07-09 22:15:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 731 ms / 1,500 ms
コード長 1,094 bytes
コンパイル時間 1,554 ms
コンパイル使用メモリ 171,972 KB
実行使用メモリ 4,908 KB
最終ジャッジ日時 2023-09-14 09:29:14
合計ジャッジ時間 13,003 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 628 ms
4,748 KB
testcase_04 AC 679 ms
4,628 KB
testcase_05 AC 731 ms
4,740 KB
testcase_06 AC 705 ms
4,656 KB
testcase_07 AC 724 ms
4,580 KB
testcase_08 AC 457 ms
4,576 KB
testcase_09 AC 504 ms
4,568 KB
testcase_10 AC 200 ms
4,620 KB
testcase_11 AC 153 ms
4,680 KB
testcase_12 AC 385 ms
4,656 KB
testcase_13 AC 543 ms
4,736 KB
testcase_14 AC 627 ms
4,576 KB
testcase_15 AC 139 ms
4,580 KB
testcase_16 AC 240 ms
4,892 KB
testcase_17 AC 259 ms
4,576 KB
testcase_18 AC 664 ms
4,744 KB
testcase_19 AC 670 ms
4,720 KB
testcase_20 AC 665 ms
4,576 KB
testcase_21 AC 437 ms
4,908 KB
testcase_22 AC 229 ms
4,636 KB
testcase_23 AC 213 ms
4,616 KB
testcase_24 AC 47 ms
4,580 KB
testcase_25 AC 45 ms
4,624 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

int main(){
    ll n, k, p; cin >> n >> k >> p;
    VI a(n), b(n);
    REP(i,n) cin >> a[i], a[i]%=p;
    REP(i,n) cin >> b[i], b[i]%=p;
    sort(ALL(b));
    ll l=-1, r=p;
    while(r-l>1){
        ll m=(l+r)/2;
        ll sum=0;
        REP(i,n){
            if(a[i]<=m)
                sum+=upper_bound(ALL(b),m-a[i])-b.begin();
            sum+=upper_bound(ALL(b),p-max(0LL,a[i]-m))-lower_bound(ALL(b),p-a[i]);
            //cout << a[i] << " " << p-max(0LL,a[i]-m) << " " << p-a[i] << endl;
        }
        //cout << m << " " << sum << endl;
        if(sum>=k)
            r=m;
        else
            l=m;
    }
    cout << r << endl;
    return 0;
}
0