結果

問題 No.1597 Matrix Sort
ユーザー H3PO4H3PO4
提出日時 2023-03-29 14:31:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 602 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 81,648 KB
実行使用メモリ 173,088 KB
最終ジャッジ日時 2023-10-21 06:10:14
合計ジャッジ時間 9,568 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
53,432 KB
testcase_01 AC 44 ms
53,432 KB
testcase_02 AC 44 ms
53,432 KB
testcase_03 WA -
testcase_04 AC 309 ms
173,032 KB
testcase_05 AC 374 ms
173,060 KB
testcase_06 AC 376 ms
173,028 KB
testcase_07 AC 285 ms
169,840 KB
testcase_08 AC 274 ms
169,800 KB
testcase_09 AC 278 ms
169,800 KB
testcase_10 AC 176 ms
169,432 KB
testcase_11 AC 191 ms
172,356 KB
testcase_12 AC 133 ms
93,728 KB
testcase_13 AC 211 ms
102,672 KB
testcase_14 AC 348 ms
173,012 KB
testcase_15 AC 140 ms
94,672 KB
testcase_16 AC 174 ms
102,612 KB
testcase_17 AC 288 ms
172,988 KB
testcase_18 WA -
testcase_19 AC 273 ms
173,024 KB
testcase_20 WA -
testcase_21 AC 235 ms
173,020 KB
testcase_22 AC 222 ms
172,960 KB
testcase_23 WA -
testcase_24 AC 97 ms
99,236 KB
testcase_25 AC 91 ms
99,236 KB
testcase_26 WA -
testcase_27 AC 40 ms
53,432 KB
testcase_28 AC 39 ms
53,432 KB
testcase_29 AC 99 ms
137,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K, P = map(int, input().split())
A = tuple(int(x) % P for x in input().split())
B = sorted(int(x) % P for x in input().split())

B_counter = [0] * P
for b in B:
    B_counter[b] += 1
for i in range(1, P):
    B_counter[i] += B_counter[i - 1]


def lower(x):
    ct = 0
    for a in A:
        i1 = x - a
        if i1 < 0: i1 = 0
        i2 = P + x - a
        if i2 >= P: i2 = P - 1
        
        ct += B_counter[i1] + B_counter[i2] - B_counter[P - a - 1]
    return ct


l, r = 0, P
while r - l > 1:
    m = (r + l) // 2
    if lower(m) >= K:
        r = m
    else:
        l = m
print(l + 1)
0