結果

問題 No.1597 Matrix Sort
ユーザー tnakao0123tnakao0123
提出日時 2021-07-12 12:57:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 613 ms / 1,500 ms
コード長 1,303 bytes
コンパイル時間 771 ms
コンパイル使用メモリ 90,632 KB
実行使用メモリ 120,868 KB
最終ジャッジ日時 2023-09-14 20:33:04
合計ジャッジ時間 12,967 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,632 KB
testcase_01 AC 2 ms
7,628 KB
testcase_02 AC 3 ms
7,640 KB
testcase_03 AC 572 ms
120,664 KB
testcase_04 AC 608 ms
120,720 KB
testcase_05 AC 613 ms
120,736 KB
testcase_06 AC 590 ms
120,868 KB
testcase_07 AC 589 ms
120,708 KB
testcase_08 AC 571 ms
63,016 KB
testcase_09 AC 591 ms
63,092 KB
testcase_10 AC 535 ms
46,484 KB
testcase_11 AC 548 ms
46,884 KB
testcase_12 AC 21 ms
7,668 KB
testcase_13 AC 77 ms
17,868 KB
testcase_14 AC 588 ms
120,660 KB
testcase_15 AC 21 ms
7,612 KB
testcase_16 AC 68 ms
17,856 KB
testcase_17 AC 566 ms
118,292 KB
testcase_18 AC 587 ms
120,656 KB
testcase_19 AC 572 ms
120,720 KB
testcase_20 AC 573 ms
120,252 KB
testcase_21 AC 568 ms
120,348 KB
testcase_22 AC 582 ms
83,480 KB
testcase_23 AC 550 ms
58,824 KB
testcase_24 AC 17 ms
7,624 KB
testcase_25 AC 16 ms
7,784 KB
testcase_26 AC 2 ms
7,560 KB
testcase_27 AC 3 ms
7,680 KB
testcase_28 AC 2 ms
7,692 KB
testcase_29 AC 538 ms
95,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1597.cc:  No.1597 Matrix Sort - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_P = 10000000;

/* typedef */

typedef long long ll;

/* global variables */

int acs[MAX_P], bcs[MAX_P], bcss[MAX_P + 1];

/* subroutines */

void readcs(int n, int cs[]) {
  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    cs[ai]++;
  }
}

ll check(int p, int x) {
  ll sum = 0;
  for (int a = 0; a < p; a++) {
    // (a+b)%p<x -> a+b<x or p<=a+b<x+p -> b<x-a or p-a<=b<x+p-a
    int bc = bcss[max(x - a, 0)] + bcss[min(x + p - a, p)] - bcss[p - a];
    sum += (ll)acs[a] * bc;
  }
  return sum;
}

/* main */

int main() {
  int n, p;
  ll k;
  scanf("%d%lld%d", &n, &k, &p);

  readcs(n, acs);
  readcs(n, bcs);

  for (int i = 0; i < p; i++) bcss[i + 1] = bcss[i] + bcs[i];

  int x0 = 0, x1 = p;
  while (x0 + 1 < x1) {
    int x = (x0 + x1) / 2;
    if (check(p, x) >= k) x1 = x;
    else x0 = x;
  }

  printf("%d\n", x0);
  return 0;
}
0