結果

問題 No.1597 Matrix Sort
ユーザー ironairona
提出日時 2021-07-10 11:09:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,687 bytes
コンパイル時間 3,696 ms
コンパイル使用メモリ 229,348 KB
実行使用メモリ 82,940 KB
最終ジャッジ日時 2023-09-14 18:49:06
合計ジャッジ時間 7,991 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 WA -
testcase_04 AC 143 ms
82,744 KB
testcase_05 AC 145 ms
82,744 KB
testcase_06 AC 145 ms
82,880 KB
testcase_07 AC 141 ms
82,588 KB
testcase_08 AC 135 ms
82,740 KB
testcase_09 AC 134 ms
82,636 KB
testcase_10 AC 92 ms
82,872 KB
testcase_11 AC 102 ms
82,684 KB
testcase_12 AC 66 ms
4,696 KB
testcase_13 AC 90 ms
12,384 KB
testcase_14 AC 147 ms
82,684 KB
testcase_15 AC 59 ms
4,636 KB
testcase_16 AC 83 ms
12,292 KB
testcase_17 AC 117 ms
82,940 KB
testcase_18 AC 135 ms
82,596 KB
testcase_19 AC 125 ms
82,760 KB
testcase_20 AC 112 ms
82,616 KB
testcase_21 AC 109 ms
82,908 KB
testcase_22 AC 102 ms
82,640 KB
testcase_23 AC 97 ms
82,592 KB
testcase_24 AC 36 ms
4,620 KB
testcase_25 AC 34 ms
4,568 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 33 ms
81,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0