結果
問題 | No.1597 Matrix Sort |
ユーザー |
![]() |
提出日時 | 2021-07-10 00:09:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 783 ms / 1,500 ms |
コード長 | 948 bytes |
コンパイル時間 | 2,072 ms |
コンパイル使用メモリ | 172,620 KB |
実行使用メモリ | 5,712 KB |
最終ジャッジ日時 | 2024-07-01 19:00:28 |
合計ジャッジ時間 | 14,338 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#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; }