結果

問題 No.1597 Matrix Sort
ユーザー 👑 rin204rin204
提出日時 2021-07-09 22:13:01
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,304 ms / 1,500 ms
コード長 602 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 102,240 KB
最終ジャッジ日時 2023-09-14 09:24:43
合計ジャッジ時間 23,963 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,220 KB
testcase_01 AC 66 ms
71,360 KB
testcase_02 AC 68 ms
71,156 KB
testcase_03 AC 1,134 ms
98,848 KB
testcase_04 AC 1,186 ms
98,812 KB
testcase_05 AC 1,138 ms
99,264 KB
testcase_06 AC 1,157 ms
98,924 KB
testcase_07 AC 1,169 ms
98,780 KB
testcase_08 AC 1,304 ms
98,580 KB
testcase_09 AC 962 ms
98,552 KB
testcase_10 AC 709 ms
100,680 KB
testcase_11 AC 568 ms
98,752 KB
testcase_12 AC 698 ms
100,128 KB
testcase_13 AC 969 ms
100,136 KB
testcase_14 AC 1,150 ms
98,632 KB
testcase_15 AC 677 ms
100,284 KB
testcase_16 AC 996 ms
99,996 KB
testcase_17 AC 1,080 ms
98,652 KB
testcase_18 AC 1,112 ms
98,888 KB
testcase_19 AC 1,094 ms
98,940 KB
testcase_20 AC 1,076 ms
98,544 KB
testcase_21 AC 1,050 ms
98,896 KB
testcase_22 AC 1,164 ms
99,208 KB
testcase_23 AC 1,113 ms
100,820 KB
testcase_24 AC 149 ms
102,240 KB
testcase_25 AC 129 ms
101,940 KB
testcase_26 AC 64 ms
71,388 KB
testcase_27 AC 65 ms
71,344 KB
testcase_28 AC 64 ms
71,468 KB
testcase_29 AC 74 ms
75,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect_right

n, k, p = map(int, input().split())
alst = list(map(int, input().split()))
blst = list(map(int, input().split()))
alst.sort()
blst.sort()

def ok(x):
    cnt = 0
    for a in alst:
        b_min = p - a
        b_max = (x - a) % p
        p1 = bisect_right(blst, b_max)
        p2 = bisect_left(blst, b_min)
        if b_max >= b_min:
            cnt += p1 - p2
        else:
            cnt += p1 + n - p2
    
    return cnt >= k

l = -1
r = p - 1
while r - l > 1:
    mid = (r + l) // 2
    if ok(mid):
        r = mid
    else:
        l = mid
print(r)
0