結果

問題 No.1597 Matrix Sort
ユーザー HaaHaa
提出日時 2021-07-09 22:15:36
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 749 ms / 1,500 ms
コード長 1,094 bytes
コンパイル時間 1,411 ms
使用メモリ 6,952 KB
最終ジャッジ日時 2023-02-02 00:03:18
合計ジャッジ時間 13,260 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
4,900 KB
testcase_01 AC 1 ms
4,904 KB
testcase_02 AC 1 ms
6,952 KB
testcase_03 AC 649 ms
4,904 KB
testcase_04 AC 703 ms
6,952 KB
testcase_05 AC 745 ms
4,904 KB
testcase_06 AC 727 ms
6,952 KB
testcase_07 AC 749 ms
4,900 KB
testcase_08 AC 473 ms
6,948 KB
testcase_09 AC 527 ms
6,948 KB
testcase_10 AC 195 ms
6,952 KB
testcase_11 AC 150 ms
4,904 KB
testcase_12 AC 391 ms
4,904 KB
testcase_13 AC 556 ms
4,904 KB
testcase_14 AC 642 ms
4,900 KB
testcase_15 AC 134 ms
6,952 KB
testcase_16 AC 231 ms
4,904 KB
testcase_17 AC 255 ms
4,904 KB
testcase_18 AC 683 ms
4,900 KB
testcase_19 AC 689 ms
4,900 KB
testcase_20 AC 686 ms
4,904 KB
testcase_21 AC 455 ms
6,948 KB
testcase_22 AC 220 ms
6,952 KB
testcase_23 AC 213 ms
4,900 KB
testcase_24 AC 45 ms
6,948 KB
testcase_25 AC 44 ms
4,904 KB
testcase_26 AC 1 ms
4,900 KB
testcase_27 AC 1 ms
6,948 KB
testcase_28 AC 1 ms
4,904 KB
testcase_29 AC 1 ms
4,904 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