結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 629 ms
4,564 KB
testcase_04 AC 684 ms
4,680 KB
testcase_05 AC 727 ms
4,628 KB
testcase_06 AC 710 ms
4,760 KB
testcase_07 AC 717 ms
4,788 KB
testcase_08 AC 454 ms
4,756 KB
testcase_09 AC 498 ms
4,696 KB
testcase_10 AC 198 ms
4,516 KB
testcase_11 AC 153 ms
4,816 KB
testcase_12 AC 381 ms
4,584 KB
testcase_13 AC 542 ms
4,464 KB
testcase_14 AC 624 ms
4,516 KB
testcase_15 AC 140 ms
4,524 KB
testcase_16 AC 237 ms
4,688 KB
testcase_17 AC 260 ms
4,524 KB
testcase_18 AC 662 ms
4,680 KB
testcase_19 AC 670 ms
4,512 KB
testcase_20 AC 669 ms
4,680 KB
testcase_21 AC 437 ms
4,468 KB
testcase_22 AC 231 ms
4,640 KB
testcase_23 AC 212 ms
4,460 KB
testcase_24 AC 46 ms
4,524 KB
testcase_25 AC 46 ms
4,580 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 2 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