結果

問題 No.1597 Matrix Sort
ユーザー miscalcmiscalc
提出日時 2021-07-09 23:52:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 208 ms / 1,500 ms
コード長 1,689 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 168,856 KB
実行使用メモリ 161,068 KB
最終ジャッジ日時 2023-09-14 11:19:10
合計ジャッジ時間 6,501 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 197 ms
160,800 KB
testcase_04 AC 204 ms
160,812 KB
testcase_05 AC 203 ms
160,752 KB
testcase_06 AC 203 ms
161,004 KB
testcase_07 AC 208 ms
160,752 KB
testcase_08 AC 191 ms
160,804 KB
testcase_09 AC 193 ms
160,792 KB
testcase_10 AC 141 ms
160,752 KB
testcase_11 AC 151 ms
160,788 KB
testcase_12 AC 52 ms
4,936 KB
testcase_13 AC 88 ms
20,180 KB
testcase_14 AC 203 ms
160,760 KB
testcase_15 AC 49 ms
4,644 KB
testcase_16 AC 72 ms
20,240 KB
testcase_17 AC 163 ms
161,068 KB
testcase_18 AC 200 ms
160,804 KB
testcase_19 AC 192 ms
160,860 KB
testcase_20 AC 160 ms
160,944 KB
testcase_21 AC 150 ms
160,748 KB
testcase_22 AC 148 ms
161,068 KB
testcase_23 AC 144 ms
160,812 KB
testcase_24 AC 31 ms
4,548 KB
testcase_25 AC 30 ms
4,604 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 85 ms
159,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

ll N, K, P;
vector<ll> A, B, S;

void accum(vector<ll> &s)
{
  s.resize(2 * P, 0);
  for (ll i = 0; i < N; i++)
  {
    s.at(A.at(i))++;
    s.at(P + A.at(i))++;
  }

  /*
  for (ll i = 0; i < 2 * P; i++)
  {
    cerr << i << " " << s.at(i) << endl;
  }
  //*/

  for (ll i = 0; i < 2 * P - 1; i++)
  {
    s.at(i + 1) += s.at(i);
  }
}

ll count(ll t)
{
  ll ret = 0;
  for (ll i = 0; i < N; i++)
  {
    ll tmp = S.at(P + t - B.at(i)) - S.at(P - B.at(i) - 1);
    ret += tmp;
  }
  return ret;
}

bool isok(ll t)
{
  return count(t) >= K;
}

int main()
{
  cin >> N >> K >> P;
  A.resize(N), B.resize(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  for (ll i = 0; i < N; i++)
  {
    cin >> B.at(i);
  }

  accum(S);

  /*
  for (ll i = 0; i < 2 * P; i++)
  {
    cerr << i << " " << S.at(i) << endl;
  }
  //*/

  ll ng = -1, ok = P - 1;
  while (abs(ok - ng) > 1)
  {
    ll mid = (ok + ng) / 2;
    if (isok(mid))
      ok = mid;
    else
      ng = mid;
  }
  cout << ok << endl;

  /*
  for (ll p = 0; p < P; p++)
  {
    cerr << count(p) << endl;
  }
  //*/
}
0