結果

問題 No.1597 Matrix Sort
ユーザー rin204rin204
提出日時 2021-07-09 22:13:01
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 1,292 ms / 1,500 ms
コード長 602 bytes
コンパイル時間 280 ms
使用メモリ 106,012 KB
最終ジャッジ日時 2023-02-01 23:57:21
合計ジャッジ時間 24,538 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 75 ms
75,776 KB
testcase_01 AC 75 ms
75,776 KB
testcase_02 AC 77 ms
75,848 KB
testcase_03 AC 1,151 ms
99,788 KB
testcase_04 AC 1,210 ms
99,880 KB
testcase_05 AC 1,228 ms
99,656 KB
testcase_06 AC 1,184 ms
99,860 KB
testcase_07 AC 1,157 ms
99,952 KB
testcase_08 AC 1,292 ms
99,920 KB
testcase_09 AC 938 ms
99,860 KB
testcase_10 AC 690 ms
102,532 KB
testcase_11 AC 558 ms
99,940 KB
testcase_12 AC 718 ms
104,240 KB
testcase_13 AC 1,019 ms
101,648 KB
testcase_14 AC 1,212 ms
99,664 KB
testcase_15 AC 671 ms
104,324 KB
testcase_16 AC 978 ms
101,596 KB
testcase_17 AC 1,072 ms
99,880 KB
testcase_18 AC 1,187 ms
99,652 KB
testcase_19 AC 1,075 ms
99,964 KB
testcase_20 AC 1,033 ms
99,936 KB
testcase_21 AC 1,079 ms
100,380 KB
testcase_22 AC 1,079 ms
100,480 KB
testcase_23 AC 1,011 ms
101,784 KB
testcase_24 AC 163 ms
105,808 KB
testcase_25 AC 136 ms
106,012 KB
testcase_26 AC 75 ms
75,496 KB
testcase_27 AC 73 ms
75,744 KB
testcase_28 AC 75 ms
75,840 KB
testcase_29 AC 84 ms
80,124 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