結果

問題 No.1597 Matrix Sort
ユーザー alorie10alorie10
提出日時 2021-07-10 00:09:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 753 ms / 1,500 ms
コード長 948 bytes
コンパイル時間 1,649 ms
コンパイル使用メモリ 170,228 KB
実行使用メモリ 5,620 KB
最終ジャッジ日時 2023-09-14 11:32:36
合計ジャッジ時間 14,205 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 696 ms
5,400 KB
testcase_04 AC 746 ms
5,300 KB
testcase_05 AC 753 ms
5,464 KB
testcase_06 AC 723 ms
5,372 KB
testcase_07 AC 739 ms
5,404 KB
testcase_08 AC 507 ms
5,324 KB
testcase_09 AC 529 ms
5,324 KB
testcase_10 AC 233 ms
5,344 KB
testcase_11 AC 199 ms
5,244 KB
testcase_12 AC 417 ms
5,396 KB
testcase_13 AC 591 ms
5,468 KB
testcase_14 AC 660 ms
5,244 KB
testcase_15 AC 166 ms
5,420 KB
testcase_16 AC 275 ms
5,620 KB
testcase_17 AC 312 ms
5,484 KB
testcase_18 AC 708 ms
5,244 KB
testcase_19 AC 717 ms
5,324 KB
testcase_20 AC 707 ms
5,368 KB
testcase_21 AC 466 ms
5,364 KB
testcase_22 AC 274 ms
5,308 KB
testcase_23 AC 247 ms
5,468 KB
testcase_24 AC 44 ms
5,404 KB
testcase_25 AC 42 ms
5,240 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,MOD,a,b,ans,bik[400001],c,st,go,mid;
vector<ll> v,u;
ll f(ll mid){
    ll tot=0;
    for(int i=0;i<n;i++){
        ll A=upper_bound(u.begin(),u.end(),mid-v[i])-u.begin();
        ll B=lower_bound(u.begin(),u.end(),0-v[i])-u.begin();
        ll C=upper_bound(u.begin(),u.end(),mid-v[i]+MOD)-u.begin();
        ll D=lower_bound(u.begin(),u.end(),0-v[i]+MOD)-u.begin();
        tot+=A-B+C-D;
        //cout<<A<<" "<<B<<" "<<C<<" "<<D<<endl;
    }
    //cout<<tot<<" "<<mid<<endl;
    return tot;
}
int main(void){
    cin>>n>>m>>MOD;
    for(int i=0;i<n;i++){
        cin>>a;
        v.push_back(a%MOD);
    }
    for(int i=0;i<n;i++){
        cin>>a;
        u.push_back(a%MOD);
    }
    sort(u.begin(),u.end());
    st=-1,go=MOD-1;
    while(go-st>1){
        mid=(st+go)/2;
        ll tmp=f(mid);
        if(tmp>=m)go=mid;
        else st=mid;
    }
    cout<<go<<endl;
}
0