結果

問題 No.1597 Matrix Sort
ユーザー ocvret_ocvret_
提出日時 2021-07-11 10:43:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 389 ms / 1,500 ms
コード長 1,007 bytes
コンパイル時間 2,151 ms
コンパイル使用メモリ 169,100 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 20:06:54
合計ジャッジ時間 9,120 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 356 ms
4,376 KB
testcase_04 AC 383 ms
4,380 KB
testcase_05 AC 389 ms
4,376 KB
testcase_06 AC 376 ms
4,376 KB
testcase_07 AC 387 ms
4,376 KB
testcase_08 AC 294 ms
4,380 KB
testcase_09 AC 301 ms
4,380 KB
testcase_10 AC 197 ms
4,380 KB
testcase_11 AC 190 ms
4,380 KB
testcase_12 AC 165 ms
4,376 KB
testcase_13 AC 298 ms
4,376 KB
testcase_14 AC 330 ms
4,376 KB
testcase_15 AC 127 ms
4,376 KB
testcase_16 AC 184 ms
4,376 KB
testcase_17 AC 214 ms
4,380 KB
testcase_18 AC 370 ms
4,376 KB
testcase_19 AC 257 ms
4,376 KB
testcase_20 AC 205 ms
4,380 KB
testcase_21 AC 200 ms
4,380 KB
testcase_22 AC 203 ms
4,380 KB
testcase_23 AC 192 ms
4,380 KB
testcase_24 AC 46 ms
4,380 KB
testcase_25 AC 44 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  ll n,K,p;
  cin >> n >> K >> p;
  vector<int> a(n),b(n);
  rep(i,n)cin >> a[i],a[i] %= p;
  rep(i,n)cin >> b[i],b[i] %= p;
  sort(ALL(a));
  sort(ALL(b));
  ll l = -1,r = p;
  while(r-l > 1){
    ll mid = (l+r)/2;
    ll cnt = 0;
    rep(i,n){
      int mn = mid-a[i],mx = p + mid - a[i];
      {
        auto iter = lower_bound(ALL(b),mn+1);
        cnt += iter - b.begin();
      }
      {
        auto ml = lower_bound(ALL(b),p-a[i]);
        auto mr = lower_bound(ALL(b),p+mid-a[i]+1);
        cnt += mr-ml;
      }
    }
    if(cnt >= K)r = mid;
    else l = mid;
  }
  cout << r << "\n";
  

  return 0;
}
0