結果

問題 No.1597 Matrix Sort
ユーザー alorie10alorie10
提出日時 2021-07-10 00:07:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 947 bytes
コンパイル時間 1,645 ms
コンパイル使用メモリ 170,608 KB
実行使用メモリ 5,644 KB
最終ジャッジ日時 2023-09-14 11:30:47
合計ジャッジ時間 14,196 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 742 ms
5,456 KB
testcase_05 AC 755 ms
5,376 KB
testcase_06 AC 726 ms
5,456 KB
testcase_07 AC 739 ms
5,320 KB
testcase_08 AC 505 ms
5,408 KB
testcase_09 AC 533 ms
5,368 KB
testcase_10 AC 232 ms
5,624 KB
testcase_11 AC 198 ms
5,324 KB
testcase_12 AC 419 ms
5,296 KB
testcase_13 AC 591 ms
5,320 KB
testcase_14 AC 659 ms
5,468 KB
testcase_15 AC 163 ms
5,300 KB
testcase_16 AC 272 ms
5,300 KB
testcase_17 AC 316 ms
5,328 KB
testcase_18 AC 720 ms
5,328 KB
testcase_19 AC 718 ms
5,328 KB
testcase_20 AC 707 ms
5,352 KB
testcase_21 AC 466 ms
5,628 KB
testcase_22 AC 273 ms
5,620 KB
testcase_23 AC 245 ms
5,292 KB
testcase_24 AC 35 ms
5,332 KB
testcase_25 AC 33 ms
5,468 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 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=0,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