結果
問題 | No.1597 Matrix Sort |
ユーザー |
|
提出日時 | 2021-07-10 11:09:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,687 bytes |
コンパイル時間 | 3,964 ms |
コンパイル使用メモリ | 231,532 KB |
実行使用メモリ | 83,072 KB |
最終ジャッジ日時 | 2024-07-02 01:50:34 |
合計ジャッジ時間 | 8,582 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 WA * 2 |
ソースコード
#include<bits/stdc++.h> #include <atcoder/all> #define ll long long int #define vec vector<ll> #define mat vector<vector<ll>> #define pll pair<ll,ll> #define count __builtin_popcountll using namespace std; using namespace atcoder; //using mint = modint1000000007; const ll mod=1000000007;//998244353; const ll inf=1000000000000000000; ll dx4[4]={1,0,-1,0}; ll dy4[4]={0,-1,0,1}; ll dx8[8]={1,0,-1,1,-1,1,0,-1}; ll dy8[8]={1,1,1,0,0,-1,-1,-1}; int main(){ cout << fixed << setprecision(15); ll n,k,p; cin >> n >> k >> p; vec a(n),b(n); for(ll i=0;i<n;i++)cin >> a[i]; for(ll i=0;i<n;i++)cin >> b[i]; for(ll i=0;i<n;i++){ a[i]%=p; b[i]%=p; } sort(a.begin(),a.end()); sort(b.begin(),b.end()); vec s(p); for(ll i=0;i<n;i++){ s[b[i]]++; } for(ll i=0;i<p-1;i++){ s[i+1]+=s[i]; } // ll s=0; // for(ll i=0;i<n;i++){ // if(a[i]<2){ // s+=upper_bound(b.begin(),b.end(),2-a[i])-b.begin()-1; // s+=n-(upper_bound(b.begin(),b.end(),p-a[i])-b.begin()); // } // else{ // s+=upper_bound(b.begin(),b.end(),(2-a[i]+p)%p)-lower_bound(b.begin(),b.end(),p-a[i]); // } // cout << s << endl; // } // cout << s << endl; ll l=0,r=p,h=(r+l)/2; while(abs(r-l)>1){ ll ret=0; for(ll i=0;i<n;i++){ if(a[i]<=h){ ret+=s[h-a[i]]; ret+=n-s[p-a[i]-1]; } // else if(h==a[i]){ // s+=n-(lower_bound(b.begin(),b.end(),p-a[i])-b.begin()); // } else{ ret+=s[h-a[i]+p]-s[p-a[i]-1]; } } if(ret>=k)r=h; else l=h; h=(r+l)/2; // cout << r << " " << l << endl; } cout << r << endl; return 0; }