結果

問題 No.1597 Matrix Sort
ユーザー SSRSSSRS
提出日時 2021-07-09 21:39:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 359 ms / 1,500 ms
コード長 870 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 170,508 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 08:08:20
合計ジャッジ時間 8,319 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 333 ms
4,380 KB
testcase_04 AC 359 ms
4,380 KB
testcase_05 AC 355 ms
4,380 KB
testcase_06 AC 341 ms
4,376 KB
testcase_07 AC 338 ms
4,384 KB
testcase_08 AC 269 ms
4,384 KB
testcase_09 AC 268 ms
4,380 KB
testcase_10 AC 152 ms
4,384 KB
testcase_11 AC 127 ms
4,384 KB
testcase_12 AC 147 ms
4,504 KB
testcase_13 AC 275 ms
4,380 KB
testcase_14 AC 306 ms
4,380 KB
testcase_15 AC 104 ms
4,380 KB
testcase_16 AC 151 ms
4,380 KB
testcase_17 AC 173 ms
4,376 KB
testcase_18 AC 341 ms
4,380 KB
testcase_19 AC 229 ms
4,380 KB
testcase_20 AC 169 ms
4,376 KB
testcase_21 AC 159 ms
4,380 KB
testcase_22 AC 157 ms
4,380 KB
testcase_23 AC 138 ms
4,384 KB
testcase_24 AC 38 ms
4,384 KB
testcase_25 AC 35 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  long long K;
  int P;
  cin >> N >> K >> P;
  K--;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
    A[i] = (P - A[i]) % P;
  }
  sort(A.begin(), A.end());
  vector<int> B(N);
  for (int i = 0; i < N; i++){
    cin >> B[i];
  }
  sort(B.begin(), B.end());
  int tv = 0, fv = P;
  while (fv - tv > 1){
    int mid = (tv + fv) / 2;
    long long cnt = 0;
    for (int i = 0; i < N; i++){
      if (A[i] + mid < P){
        cnt += lower_bound(B.begin(), B.end(), A[i] + mid) - lower_bound(B.begin(), B.end(), A[i]);
      } else {
        cnt += B.end() - lower_bound(B.begin(), B.end(), A[i]);
        cnt += lower_bound(B.begin(), B.end(), A[i] + mid - P) - B.begin();
      }
    }
    if (cnt <= K){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  cout << tv << endl;
}
0