結果

問題 No.1597 Matrix Sort
ユーザー wolgnikwolgnik
提出日時 2021-07-09 22:30:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 361 ms / 1,500 ms
コード長 530 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 246,456 KB
最終ジャッジ日時 2023-09-14 09:47:20
合計ジャッジ時間 8,027 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,556 KB
testcase_01 AC 69 ms
71,332 KB
testcase_02 AC 69 ms
71,356 KB
testcase_03 AC 296 ms
246,248 KB
testcase_04 AC 298 ms
246,444 KB
testcase_05 AC 361 ms
246,304 KB
testcase_06 AC 357 ms
246,188 KB
testcase_07 AC 292 ms
246,184 KB
testcase_08 AC 265 ms
246,100 KB
testcase_09 AC 267 ms
246,132 KB
testcase_10 AC 216 ms
245,968 KB
testcase_11 AC 224 ms
246,296 KB
testcase_12 AC 129 ms
102,360 KB
testcase_13 AC 163 ms
105,440 KB
testcase_14 AC 334 ms
246,168 KB
testcase_15 AC 140 ms
102,556 KB
testcase_16 AC 164 ms
105,752 KB
testcase_17 AC 264 ms
246,456 KB
testcase_18 AC 321 ms
246,356 KB
testcase_19 AC 272 ms
246,300 KB
testcase_20 AC 245 ms
246,252 KB
testcase_21 AC 245 ms
246,260 KB
testcase_22 AC 249 ms
246,152 KB
testcase_23 AC 238 ms
246,084 KB
testcase_24 AC 104 ms
101,432 KB
testcase_25 AC 102 ms
101,424 KB
testcase_26 AC 68 ms
71,112 KB
testcase_27 AC 68 ms
71,444 KB
testcase_28 AC 68 ms
71,184 KB
testcase_29 AC 154 ms
232,172 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