結果

問題 No.1597 Matrix Sort
ユーザー 👑 tamatotamato
提出日時 2021-07-09 22:29:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 415 ms / 1,500 ms
コード長 1,396 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 103,624 KB
最終ジャッジ日時 2023-09-14 09:44:22
合計ジャッジ時間 9,637 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,756 KB
testcase_01 AC 69 ms
71,556 KB
testcase_02 AC 69 ms
71,764 KB
testcase_03 AC 393 ms
98,376 KB
testcase_04 AC 412 ms
98,460 KB
testcase_05 AC 413 ms
98,468 KB
testcase_06 AC 407 ms
98,428 KB
testcase_07 AC 415 ms
98,440 KB
testcase_08 AC 298 ms
98,628 KB
testcase_09 AC 269 ms
98,492 KB
testcase_10 AC 165 ms
99,828 KB
testcase_11 AC 183 ms
98,456 KB
testcase_12 AC 252 ms
99,488 KB
testcase_13 AC 364 ms
100,344 KB
testcase_14 AC 382 ms
98,480 KB
testcase_15 AC 258 ms
102,528 KB
testcase_16 AC 343 ms
100,300 KB
testcase_17 AC 371 ms
98,560 KB
testcase_18 AC 402 ms
98,576 KB
testcase_19 AC 355 ms
98,500 KB
testcase_20 AC 337 ms
98,776 KB
testcase_21 AC 285 ms
98,720 KB
testcase_22 AC 306 ms
99,172 KB
testcase_23 AC 303 ms
99,988 KB
testcase_24 AC 133 ms
103,544 KB
testcase_25 AC 116 ms
103,624 KB
testcase_26 AC 70 ms
71,836 KB
testcase_27 AC 67 ms
71,696 KB
testcase_28 AC 69 ms
71,768 KB
testcase_29 AC 71 ms
71,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    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()
    A.reverse()

    ok = P-1
    ng = -1
    mid = (ok + ng) // 2
    while ok - ng > 1:
        cnt = 0
        i0 = i1 = i2 = 0
        for i in range(N):
            if B[i] <= mid - A[0]:
                i0 = i+1
            if B[i] < P - A[0]:
                i1 = i+1
            if B[i] <= mid + P - A[0]:
                i2 = i+1
        for a in A:
            while True:
                flg = 0
                if i0 < N:
                    if B[i0] <= mid - a:
                        i0 += 1
                        flg = 1
                if i1 < N:
                    if B[i1] < P - a:
                        i1 += 1
                        flg = 1
                if i2 < N:
                    if B[i2] <= mid + P - a:
                        i2 += 1
                        flg = 1
                if not flg:
                    break
            #print(i0, i1, i2)
            cnt += i0 + i2 - i1
        if cnt >= K:
            ok = mid
        else:
            ng = mid
        #print(ok, ng)
        mid = (ok + ng) // 2
    print(ok)


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