結果

問題 No.1597 Matrix Sort
ユーザー hayatenhayaten
提出日時 2021-07-09 23:57:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 349 ms / 1,500 ms
コード長 1,666 bytes
コンパイル時間 5,103 ms
コンパイル使用メモリ 276,252 KB
実行使用メモリ 317,424 KB
最終ジャッジ日時 2023-09-14 11:23:11
合計ジャッジ時間 12,042 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 325 ms
317,140 KB
testcase_04 AC 342 ms
317,220 KB
testcase_05 AC 349 ms
317,080 KB
testcase_06 AC 349 ms
317,192 KB
testcase_07 AC 348 ms
317,128 KB
testcase_08 AC 268 ms
317,136 KB
testcase_09 AC 280 ms
317,100 KB
testcase_10 AC 212 ms
317,240 KB
testcase_11 AC 227 ms
317,172 KB
testcase_12 AC 52 ms
5,044 KB
testcase_13 AC 97 ms
35,968 KB
testcase_14 AC 294 ms
317,412 KB
testcase_15 AC 50 ms
4,884 KB
testcase_16 AC 78 ms
36,092 KB
testcase_17 AC 237 ms
317,260 KB
testcase_18 AC 284 ms
317,240 KB
testcase_19 AC 275 ms
317,100 KB
testcase_20 AC 237 ms
317,244 KB
testcase_21 AC 226 ms
317,384 KB
testcase_22 AC 225 ms
316,984 KB
testcase_23 AC 216 ms
317,424 KB
testcase_24 AC 30 ms
4,772 KB
testcase_25 AC 30 ms
4,600 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 159 ms
315,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region Macros
// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define popcount(bit) __builtin_popcount(bit)
#define popcountll(bit) __builtin_popcountll(bit)
#define pb push_back
#define eb emplace_back
using namespace std;
using namespace atcoder;
using P = pair<int, int>;
using PL = pair<long long, long long>;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int fx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int fy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  int n, p;
  ll k;
  cin >> n >> k >> p;
  vector<ll> A(n), B(n);
  vector<ll> cn_amari(2 * p);
  rep(i, n) cin >> A[i];
  rep(i, n){
    cin >> B[i];
    cn_amari[B[i]]++;
  }
  rep(i, p){
    cn_amari[p + i] = cn_amari[i];
  }
  vector<ll> cn_amari_sum(2 * p + 1);
  rep(i, 2* p){
    cn_amari_sum[i + 1] = cn_amari_sum[i] + cn_amari[i];
  }
  auto ok = [&](int d){
    ll cn = 0;
    rep(i, n){
      int start = p - A[i];
      int end = p + d - A[i];
      end++;
      cn += (cn_amari_sum[end] - cn_amari_sum[start]);
    }
    return cn >= k;
  };

  int left = -1, right = p + 1;
  while(right - left > 1){
    int mid = (left + right) / 2;
    if(ok(mid)){
      right = mid;
    }else{
      left = mid;
    }
  }
  cout << right << endl;
}
0