結果

問題 No.1597 Matrix Sort
ユーザー hangin-svghangin-svg
提出日時 2021-07-10 03:10:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 426 ms / 1,500 ms
コード長 835 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 168,960 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 15:18:13
合計ジャッジ時間 9,670 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 377 ms
4,376 KB
testcase_04 AC 392 ms
4,376 KB
testcase_05 AC 423 ms
4,376 KB
testcase_06 AC 426 ms
4,380 KB
testcase_07 AC 395 ms
4,380 KB
testcase_08 AC 316 ms
4,376 KB
testcase_09 AC 320 ms
4,376 KB
testcase_10 AC 212 ms
4,376 KB
testcase_11 AC 184 ms
4,380 KB
testcase_12 AC 164 ms
4,380 KB
testcase_13 AC 315 ms
4,376 KB
testcase_14 AC 355 ms
4,380 KB
testcase_15 AC 136 ms
4,380 KB
testcase_16 AC 194 ms
4,376 KB
testcase_17 AC 225 ms
4,380 KB
testcase_18 AC 386 ms
4,376 KB
testcase_19 AC 278 ms
4,376 KB
testcase_20 AC 213 ms
4,380 KB
testcase_21 AC 204 ms
4,376 KB
testcase_22 AC 208 ms
4,376 KB
testcase_23 AC 209 ms
4,376 KB
testcase_24 AC 46 ms
4,376 KB
testcase_25 AC 44 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int n,p;

int count(vector<int> &a,int b,int l){
  auto left = lower_bound(a.begin(), a.end(),l-b);
  auto mid = lower_bound(a.begin(), a.end(),p-b);
  auto right = lower_bound(a.begin(), a.end(),l+p-b);

  return distance(a.begin(), left) + distance(mid, right);
}

int main(){

  ll k;
  cin >> n >> k >> p;
  vector<int> a(n), b(n);
  for(int i=0; i<n; ++i) 
    cin >> a[i];
  for(int i=0; i<n; ++i)
    cin >> b[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  ll ok = -1, ng = 2*p, check = (ok+ng)/2;
  while(ng-ok>1){
    check = (ok+ng)/2;
    ll accum = 0;
    for(int i=0; i<n; ++i) {
      accum += count(a,b[i],check);
    }
    if( accum < k ) ok=check;
    else ng = check;
  }

  cout << ok << endl;


}
0