結果

問題 No.1597 Matrix Sort
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-07-09 22:01:22
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 495 ms / 1,500 ms
コード長 558 bytes
コンパイル時間 270 ms
使用メモリ 174,304 KB
最終ジャッジ日時 2023-02-01 23:28:21
合計ジャッジ時間 9,593 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 79 ms
75,776 KB
testcase_01 AC 77 ms
75,444 KB
testcase_02 AC 77 ms
75,576 KB
testcase_03 AC 352 ms
173,536 KB
testcase_04 AC 377 ms
173,544 KB
testcase_05 AC 481 ms
174,304 KB
testcase_06 AC 495 ms
174,008 KB
testcase_07 AC 350 ms
173,416 KB
testcase_08 AC 327 ms
173,768 KB
testcase_09 AC 328 ms
173,964 KB
testcase_10 AC 243 ms
172,864 KB
testcase_11 AC 256 ms
173,932 KB
testcase_12 AC 153 ms
104,472 KB
testcase_13 AC 202 ms
103,176 KB
testcase_14 AC 419 ms
173,784 KB
testcase_15 AC 166 ms
104,440 KB
testcase_16 AC 198 ms
102,924 KB
testcase_17 AC 322 ms
173,988 KB
testcase_18 AC 416 ms
173,980 KB
testcase_19 AC 351 ms
174,292 KB
testcase_20 AC 297 ms
174,180 KB
testcase_21 AC 287 ms
174,112 KB
testcase_22 AC 283 ms
173,968 KB
testcase_23 AC 260 ms
172,704 KB
testcase_24 AC 122 ms
107,280 KB
testcase_25 AC 117 ms
107,184 KB
testcase_26 AC 78 ms
75,504 KB
testcase_27 AC 77 ms
75,448 KB
testcase_28 AC 77 ms
75,704 KB
testcase_29 AC 161 ms
158,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import count


n,k,p = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sA = [a%p for a in A]
cum = [0]*p
for b in B:
    cum[b%p] += 1
for i in range(p-1):
    cum[i+1] += cum[i]

def count(x):
    ans = 0
    for a in sA:
        ans += cum[(-a%p+x)%p]
        if (-a)%p != 0:
            ans -= cum[-a%p-1]
        if (-a%p+x)%p < -a%p:
            ans += cum[-1]

    return ans
l = -1
r = p-1
while r > l+1:
    m = (r+l)//2
    if count(m) < k:
        l = m
    else:
        r = m
print(r)
0