結果

問題 No.1597 Matrix Sort
ユーザー ygd.ygd.
提出日時 2021-08-01 11:31:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,449 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 10,804 KB
実行使用メモリ 413,436 KB
最終ジャッジ日時 2023-10-14 18:42:52
合計ジャッジ時間 6,305 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,972 KB
testcase_01 AC 17 ms
8,640 KB
testcase_02 AC 17 ms
8,624 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys 
input = sys.stdin.buffer.readline

def main():
    N,K,P = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    B.sort()
    #dica = defaultdict(int)
    #dicb = defaultdict(int)
    #for a,b in zip(A,B):
    #    #dica[a%P] += 1
    #    dicb[b%P] += 1
    #print(dica,dicb)
    #この累積和のメモリが重いわけではなく辞書が重かったぽい。
    bidx = 0
    sb = [0]*(P+1)
    for i in range(P):
        cnt = 0
        while bidx < N and B[bidx] == i:
            bidx += 1
            cnt += 1
            if bidx == N:
                break
        #print(i,cnt)
        sb[i+1] = sb[i] + cnt

    #print(sb)
    #和がx以下となるのがk個以上あるか

    def solve(x):
        ret = 0
        for a in A:
            if a <= x:
                temp = sb[x-a+1] - sb[0]
                temp += sb[P] - sb[P-a]
            else:
                temp = sb[P+x-a+1] - sb[P-a]
            ret += temp
        #print(x,ret)
        return ret

    #test = 9
    #print(solve(test))

    if solve(0) >= K:
        print(0);exit()

    ok = P
    ng = 0 #これは事前にチェック

    while abs(ok-ng) > 1:
        mid = (ok+ng)//2
        #print(mid)
        if solve(mid) >= K:
            ok = mid
        else:
            ng = mid
    #print(solve(2))
    print(ok)

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