結果

問題 No.1597 Matrix Sort
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-07-09 22:01:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 423 ms / 1,500 ms
コード長 558 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 169,504 KB
最終ジャッジ日時 2023-09-14 09:02:56
合計ジャッジ時間 8,126 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,292 KB
testcase_01 AC 68 ms
71,472 KB
testcase_02 AC 66 ms
71,528 KB
testcase_03 AC 279 ms
168,168 KB
testcase_04 AC 295 ms
168,104 KB
testcase_05 AC 404 ms
169,000 KB
testcase_06 AC 423 ms
168,624 KB
testcase_07 AC 287 ms
168,096 KB
testcase_08 AC 266 ms
168,828 KB
testcase_09 AC 259 ms
168,920 KB
testcase_10 AC 200 ms
167,996 KB
testcase_11 AC 213 ms
168,952 KB
testcase_12 AC 134 ms
103,212 KB
testcase_13 AC 174 ms
101,268 KB
testcase_14 AC 343 ms
169,108 KB
testcase_15 AC 147 ms
103,460 KB
testcase_16 AC 176 ms
101,128 KB
testcase_17 AC 267 ms
169,504 KB
testcase_18 AC 332 ms
168,716 KB
testcase_19 AC 273 ms
168,652 KB
testcase_20 AC 239 ms
169,504 KB
testcase_21 AC 231 ms
168,628 KB
testcase_22 AC 244 ms
169,488 KB
testcase_23 AC 203 ms
167,908 KB
testcase_24 AC 108 ms
102,948 KB
testcase_25 AC 96 ms
102,524 KB
testcase_26 AC 65 ms
71,564 KB
testcase_27 AC 65 ms
71,472 KB
testcase_28 AC 66 ms
71,320 KB
testcase_29 AC 119 ms
153,864 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