結果

問題 No.1597 Matrix Sort
ユーザー wolgnikwolgnik
提出日時 2021-07-09 22:30:33
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 397 ms / 1,500 ms
コード長 530 bytes
コンパイル時間 326 ms
使用メモリ 252,064 KB
最終ジャッジ日時 2023-02-02 00:26:34
合計ジャッジ時間 9,710 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 72 ms
75,556 KB
testcase_01 AC 72 ms
75,788 KB
testcase_02 AC 72 ms
75,608 KB
testcase_03 AC 332 ms
250,672 KB
testcase_04 AC 348 ms
251,060 KB
testcase_05 AC 391 ms
250,724 KB
testcase_06 AC 397 ms
250,980 KB
testcase_07 AC 329 ms
250,672 KB
testcase_08 AC 312 ms
250,920 KB
testcase_09 AC 320 ms
250,688 KB
testcase_10 AC 257 ms
250,352 KB
testcase_11 AC 267 ms
250,944 KB
testcase_12 AC 134 ms
103,628 KB
testcase_13 AC 164 ms
109,452 KB
testcase_14 AC 382 ms
251,096 KB
testcase_15 AC 148 ms
103,924 KB
testcase_16 AC 170 ms
109,712 KB
testcase_17 AC 310 ms
251,072 KB
testcase_18 AC 369 ms
251,068 KB
testcase_19 AC 327 ms
250,716 KB
testcase_20 AC 293 ms
251,092 KB
testcase_21 AC 285 ms
250,968 KB
testcase_22 AC 294 ms
252,064 KB
testcase_23 AC 278 ms
250,564 KB
testcase_24 AC 110 ms
106,208 KB
testcase_25 AC 110 ms
106,108 KB
testcase_26 AC 74 ms
75,732 KB
testcase_27 AC 73 ms
75,828 KB
testcase_28 AC 73 ms
75,772 KB
testcase_29 AC 194 ms
236,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N, K, P = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

bc = [0] * P
for x in b: bc[x] += 1
cs = [0] * (P + 1)
for i in range(P): cs[i + 1] = cs[i] + bc[i]

def check(x):
  c = 0
  for y in a:
    l = (P - y) % P
    r = (P - y + x) % P
    if l <= r: c += cs[r + 1] - cs[l]
    else: c += cs[-1] - cs[l] + cs[r + 1]
  return c >= K

ok = P - 1
ng = -1
while ok - ng > 1:
  m = (ok + ng) // 2
  if check(m): ok = m
  else: ng = m
print(ok)
0