結果

問題 No.1597 Matrix Sort
ユーザー kumakumaaaaakumakumaaaaa
提出日時 2021-07-09 22:16:50
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 355 ms / 1,500 ms
コード長 1,214 bytes
コンパイル時間 1,429 ms
使用メモリ 6,952 KB
最終ジャッジ日時 2023-02-02 00:05:25
合計ジャッジ時間 7,590 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
4,904 KB
testcase_01 AC 2 ms
4,904 KB
testcase_02 AC 1 ms
4,900 KB
testcase_03 AC 307 ms
6,948 KB
testcase_04 AC 327 ms
4,900 KB
testcase_05 AC 355 ms
6,948 KB
testcase_06 AC 344 ms
4,904 KB
testcase_07 AC 355 ms
4,900 KB
testcase_08 AC 230 ms
6,948 KB
testcase_09 AC 266 ms
4,900 KB
testcase_10 AC 161 ms
4,900 KB
testcase_11 AC 109 ms
6,952 KB
testcase_12 AC 117 ms
4,900 KB
testcase_13 AC 248 ms
4,900 KB
testcase_14 AC 285 ms
4,904 KB
testcase_15 AC 87 ms
6,952 KB
testcase_16 AC 136 ms
4,904 KB
testcase_17 AC 156 ms
6,948 KB
testcase_18 AC 314 ms
4,904 KB
testcase_19 AC 200 ms
6,952 KB
testcase_20 AC 146 ms
4,900 KB
testcase_21 AC 141 ms
4,904 KB
testcase_22 AC 146 ms
4,900 KB
testcase_23 AC 149 ms
4,904 KB
testcase_24 AC 26 ms
6,952 KB
testcase_25 AC 24 ms
6,948 KB
testcase_26 AC 1 ms
4,904 KB
testcase_27 AC 1 ms
6,948 KB
testcase_28 AC 1 ms
6,948 KB
testcase_29 AC 1 ms
4,904 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