結果

問題 No.1597 Matrix Sort
ユーザー hayatenhayaten
提出日時 2021-07-09 23:55:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,665 bytes
コンパイル時間 5,006 ms
コンパイル使用メモリ 276,636 KB
実行使用メモリ 317,332 KB
最終ジャッジ日時 2023-09-14 11:20:30
合計ジャッジ時間 11,200 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 265 ms
317,152 KB
testcase_05 AC 272 ms
317,064 KB
testcase_06 AC 304 ms
317,128 KB
testcase_07 AC 263 ms
317,100 KB
testcase_08 AC 247 ms
317,088 KB
testcase_09 AC 248 ms
317,264 KB
testcase_10 AC 185 ms
317,168 KB
testcase_11 AC 199 ms
317,036 KB
testcase_12 AC 51 ms
4,992 KB
testcase_13 AC 98 ms
36,012 KB
testcase_14 AC 255 ms
317,112 KB
testcase_15 AC 50 ms
4,848 KB
testcase_16 AC 76 ms
35,856 KB
testcase_17 AC 209 ms
317,332 KB
testcase_18 AC 253 ms
317,180 KB
testcase_19 AC 240 ms
317,220 KB
testcase_20 AC 203 ms
317,312 KB
testcase_21 AC 196 ms
317,168 KB
testcase_22 AC 192 ms
317,312 KB
testcase_23 AC 188 ms
317,116 KB
testcase_24 AC 31 ms
4,592 KB
testcase_25 AC 30 ms
4,744 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 130 ms
315,584 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 = 0, right = p + 1;
  while(right - left > 1){
    int mid = (left + right) / 2;
    if(ok(mid)){
      right = mid;
    }else{
      left = mid;
    }
  }
  cout << right << endl;
}
0