結果
問題 |
No.1597 Matrix Sort
|
ユーザー |
![]() |
提出日時 | 2021-07-31 18:25:46 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,128 bytes |
コンパイル時間 | 115 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 824,844 KB |
最終ジャッジ日時 | 2024-09-16 09:38:59 |
合計ジャッジ時間 | 3,951 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 3 MLE * 1 -- * 23 |
ソースコード
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())) 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()