結果

問題 No.1597 Matrix Sort
ユーザー 👑 rin204rin204
提出日時 2021-07-09 22:13:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,453 ms / 1,500 ms
コード長 602 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,364 KB
実行使用メモリ 102,224 KB
最終ジャッジ日時 2023-09-14 09:25:39
合計ジャッジ時間 28,176 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,612 KB
testcase_01 AC 75 ms
71,332 KB
testcase_02 AC 75 ms
71,404 KB
testcase_03 AC 1,282 ms
98,776 KB
testcase_04 AC 1,365 ms
98,796 KB
testcase_05 AC 1,367 ms
98,800 KB
testcase_06 AC 1,334 ms
99,004 KB
testcase_07 AC 1,344 ms
98,928 KB
testcase_08 AC 1,453 ms
98,592 KB
testcase_09 AC 1,125 ms
98,644 KB
testcase_10 AC 903 ms
100,904 KB
testcase_11 AC 735 ms
98,500 KB
testcase_12 AC 866 ms
100,176 KB
testcase_13 AC 1,144 ms
100,232 KB
testcase_14 AC 1,360 ms
98,632 KB
testcase_15 AC 800 ms
100,408 KB
testcase_16 AC 1,124 ms
100,048 KB
testcase_17 AC 1,310 ms
98,608 KB
testcase_18 AC 1,312 ms
99,000 KB
testcase_19 AC 1,312 ms
98,724 KB
testcase_20 AC 1,337 ms
98,708 KB
testcase_21 AC 1,280 ms
98,936 KB
testcase_22 AC 1,319 ms
99,332 KB
testcase_23 AC 1,252 ms
100,876 KB
testcase_24 AC 166 ms
102,224 KB
testcase_25 AC 143 ms
101,896 KB
testcase_26 AC 74 ms
71,416 KB
testcase_27 AC 73 ms
71,492 KB
testcase_28 AC 74 ms
71,492 KB
testcase_29 AC 81 ms
75,460 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