結果

問題 No.1597 Matrix Sort
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-07-09 23:48:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,337 ms / 1,500 ms
コード長 806 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 87,024 KB
実行使用メモリ 101,816 KB
最終ジャッジ日時 2023-09-14 11:15:52
合計ジャッジ時間 26,520 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,224 KB
testcase_01 AC 69 ms
71,420 KB
testcase_02 AC 70 ms
71,340 KB
testcase_03 AC 1,276 ms
97,204 KB
testcase_04 AC 1,311 ms
97,356 KB
testcase_05 AC 1,316 ms
96,820 KB
testcase_06 AC 1,296 ms
97,512 KB
testcase_07 AC 1,309 ms
97,204 KB
testcase_08 AC 1,337 ms
97,256 KB
testcase_09 AC 1,030 ms
96,964 KB
testcase_10 AC 818 ms
99,288 KB
testcase_11 AC 659 ms
96,976 KB
testcase_12 AC 825 ms
98,844 KB
testcase_13 AC 1,135 ms
98,472 KB
testcase_14 AC 1,317 ms
97,164 KB
testcase_15 AC 775 ms
99,168 KB
testcase_16 AC 1,018 ms
98,376 KB
testcase_17 AC 1,259 ms
96,816 KB
testcase_18 AC 1,250 ms
96,896 KB
testcase_19 AC 1,279 ms
97,392 KB
testcase_20 AC 1,244 ms
96,824 KB
testcase_21 AC 1,168 ms
97,048 KB
testcase_22 AC 1,172 ms
97,428 KB
testcase_23 AC 1,057 ms
99,152 KB
testcase_24 AC 185 ms
101,816 KB
testcase_25 AC 138 ms
101,532 KB
testcase_26 AC 69 ms
71,388 KB
testcase_27 AC 70 ms
71,324 KB
testcase_28 AC 70 ms
71,276 KB
testcase_29 AC 74 ms
75,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
from sys import stdin
import sys

N,K,P = map(int,stdin.readline().split())

A = list(map(int,stdin.readline().split()))
B = list(map(int,stdin.readline().split()))

for i in range(N):
    A[i] %= P
    B[i] %= P

A.sort()
B.sort()

#print (A,B,file=sys.stderr)

l = -1
r = P-1

while r-l != 1:

    MID = (l+r)//2

    ans = 0

    for i in range(N):
        
        ZR = (P - A[i]) % P
        ZIND = bisect.bisect_left(B,ZR)

        MR = (MID-A[i]) % P
        MIND = bisect.bisect_right(B,MR)

        if ZIND == MIND or (ZIND,MIND) in ( (0,N),(N,0) ):
            if (A[0]+B[0]) % P <= MID:
                ans += N
            else:
                ans += 0
        else:
            ans += (MIND-ZIND) % N

    if ans >= K:
        r = MID
    else:
        l = MID

    

print (r)
0