結果

問題 No.1597 Matrix Sort
ユーザー SSRSSSRS
提出日時 2021-07-09 21:39:21
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 351 ms / 1,500 ms
コード長 870 bytes
コンパイル時間 1,452 ms
使用メモリ 5,156 KB
最終ジャッジ日時 2023-02-01 22:33:47
合計ジャッジ時間 8,037 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
4,900 KB
testcase_01 AC 2 ms
4,904 KB
testcase_02 AC 1 ms
4,900 KB
testcase_03 AC 326 ms
4,904 KB
testcase_04 AC 351 ms
4,904 KB
testcase_05 AC 350 ms
4,904 KB
testcase_06 AC 339 ms
4,904 KB
testcase_07 AC 335 ms
5,152 KB
testcase_08 AC 263 ms
5,152 KB
testcase_09 AC 267 ms
4,900 KB
testcase_10 AC 151 ms
4,904 KB
testcase_11 AC 125 ms
5,152 KB
testcase_12 AC 142 ms
4,904 KB
testcase_13 AC 269 ms
4,904 KB
testcase_14 AC 299 ms
4,900 KB
testcase_15 AC 101 ms
4,904 KB
testcase_16 AC 149 ms
4,900 KB
testcase_17 AC 170 ms
4,900 KB
testcase_18 AC 334 ms
4,904 KB
testcase_19 AC 224 ms
5,156 KB
testcase_20 AC 165 ms
4,904 KB
testcase_21 AC 155 ms
5,156 KB
testcase_22 AC 154 ms
4,900 KB
testcase_23 AC 137 ms
4,904 KB
testcase_24 AC 37 ms
4,900 KB
testcase_25 AC 33 ms
5,156 KB
testcase_26 AC 1 ms
4,904 KB
testcase_27 AC 1 ms
5,156 KB
testcase_28 AC 2 ms
4,904 KB
testcase_29 AC 1 ms
4,904 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