結果

問題 No.1597 Matrix Sort
ユーザー ygd.ygd.
提出日時 2021-07-31 18:17:43
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,083 bytes
コンパイル時間 1,543 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 800,404 KB
最終ジャッジ日時 2023-10-14 15:05:25
合計ジャッジ時間 8,827 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 85 ms
71,664 KB
testcase_02 AC 87 ms
71,352 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 AC 160 ms
105,244 KB
testcase_13 AC 449 ms
254,328 KB
testcase_14 TLE -
testcase_15 AC 137 ms
105,368 KB
testcase_16 AC 337 ms
259,136 KB
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 AC 122 ms
102,556 KB
testcase_25 AC 120 ms
102,832 KB
testcase_26 AC 86 ms
71,916 KB
testcase_27 AC 81 ms
71,740 KB
testcase_28 AC 81 ms
71,800 KB
testcase_29 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict 

def main():
    N,K,P = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    dica = defaultdict(int)
    dicb = defaultdict(int)
    for a,b in zip(A,B):
        dica[a%P] += 1
        dicb[b%P] += 1
    #print(dica,dicb)
    sb = [0]
    for i in range(P):
        sb.append(sb[-1] + dicb[i])
    #print(sb)
    #和がx以下となるのがk個以上あるか

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

    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