結果

問題 No.1597 Matrix Sort
ユーザー kumakumaaaaakumakumaaaaa
提出日時 2021-07-09 22:16:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 287 ms / 1,500 ms
コード長 1,214 bytes
コンパイル時間 1,612 ms
コンパイル使用メモリ 170,336 KB
実行使用メモリ 4,708 KB
最終ジャッジ日時 2023-09-14 09:31:07
合計ジャッジ時間 6,875 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 237 ms
4,668 KB
testcase_04 AC 257 ms
4,632 KB
testcase_05 AC 286 ms
4,696 KB
testcase_06 AC 280 ms
4,472 KB
testcase_07 AC 287 ms
4,692 KB
testcase_08 AC 196 ms
4,696 KB
testcase_09 AC 237 ms
4,700 KB
testcase_10 AC 153 ms
4,584 KB
testcase_11 AC 101 ms
4,584 KB
testcase_12 AC 101 ms
4,584 KB
testcase_13 AC 198 ms
4,584 KB
testcase_14 AC 228 ms
4,472 KB
testcase_15 AC 85 ms
4,572 KB
testcase_16 AC 132 ms
4,572 KB
testcase_17 AC 148 ms
4,472 KB
testcase_18 AC 247 ms
4,524 KB
testcase_19 AC 168 ms
4,632 KB
testcase_20 AC 134 ms
4,464 KB
testcase_21 AC 135 ms
4,692 KB
testcase_22 AC 138 ms
4,456 KB
testcase_23 AC 143 ms
4,692 KB
testcase_24 AC 26 ms
4,688 KB
testcase_25 AC 24 ms
4,708 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, K, mod;
  cin >> N >> K >> mod;
  vector<ll> A(N), B(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
    A.at(i) %= mod;
  }
  for (ll i = 0; i < N; ++i) {
    cin >> B.at(i);
    B.at(i) %= mod;
  }
  sort(rng(A));
  sort(rng(B));
  ll l = -1, r = mod - 1;
  while (l + 1 != r) {
    ll m = (l + r) / 2;
    ll cnt = 0;
    for (ll i = 0; i < N; ++i) {
      ll a = A.at(i);
      if (a <= m) {
        ll left = m - a;
        cnt += upper_bound(rng(B), left) - B.begin();
      }
      ll need = mod - a;
      ll cap_max = m + mod - a;
      cnt += upper_bound(rng(B), cap_max) - lower_bound(rng(B), need);
    }
    if (cnt >= K) {
      r = m;
    }
    else {
      l = m;
    }
  }
  cout << r << "\n";
}
0