結果

問題 No.1597 Matrix Sort
コンテスト
ユーザー tamato
提出日時 2021-07-09 21:44:52
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,395 ms / 1,500 ms
コード長 719 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 183 ms
コンパイル使用メモリ 85,248 KB
実行使用メモリ 110,720 KB
最終ジャッジ日時 2026-03-22 18:05:23
合計ジャッジ時間 26,311 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

mod = 1000000007
eps = 10**-9


def main():
    import sys
    from bisect import bisect_left
    input = sys.stdin.readline

    N, K, P = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    A = [a % P for a in A]
    B = [b % P for b in B]
    A.sort()
    B.sort()

    ok = P-1
    ng = -1
    mid = (ok + ng) // 2
    while ok - ng > 1:
        cnt = 0
        for a in A:
            cnt += bisect_left(B, mid - a + 1)
            cnt += bisect_left(B, P + mid - a + 1) - bisect_left(B, P - a)
        if cnt >= K:
            ok = mid
        else:
            ng = mid
        mid = (ok + ng) // 2
    print(ok)


if __name__ == '__main__':
    main()
0