結果

問題 No.1597 Matrix Sort
ユーザー 👑 KazunKazun
提出日時 2021-07-09 21:58:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 535 ms / 1,500 ms
コード長 1,233 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 87,168 KB
実行使用メモリ 321,784 KB
最終ジャッジ日時 2023-09-14 08:57:57
合計ジャッジ時間 10,767 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,324 KB
testcase_01 AC 74 ms
75,976 KB
testcase_02 AC 78 ms
75,888 KB
testcase_03 AC 336 ms
321,320 KB
testcase_04 AC 535 ms
321,208 KB
testcase_05 AC 456 ms
321,424 KB
testcase_06 AC 402 ms
321,396 KB
testcase_07 AC 381 ms
321,392 KB
testcase_08 AC 443 ms
321,692 KB
testcase_09 AC 365 ms
321,784 KB
testcase_10 AC 314 ms
320,668 KB
testcase_11 AC 335 ms
321,508 KB
testcase_12 AC 141 ms
100,016 KB
testcase_13 AC 206 ms
113,860 KB
testcase_14 AC 443 ms
321,624 KB
testcase_15 AC 150 ms
103,464 KB
testcase_16 AC 174 ms
113,404 KB
testcase_17 AC 368 ms
321,576 KB
testcase_18 AC 440 ms
321,200 KB
testcase_19 AC 386 ms
321,284 KB
testcase_20 AC 364 ms
321,268 KB
testcase_21 AC 363 ms
321,372 KB
testcase_22 AC 355 ms
320,844 KB
testcase_23 AC 369 ms
320,536 KB
testcase_24 AC 117 ms
102,300 KB
testcase_25 AC 107 ms
102,296 KB
testcase_26 AC 62 ms
71,304 KB
testcase_27 AC 65 ms
71,300 KB
testcase_28 AC 66 ms
71,456 KB
testcase_29 AC 237 ms
310,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def General_Binary_Increase_Search_Integer(L,R,cond,default=None):
    """条件式が単調増加であるとき, 整数上で二部探索を行う.
    L: 解の下限
    R: 解の上限
    cond: 条件(1変数関数, 広義単調増加を満たす)
    default: Rで条件を満たさないときの返り値
    """
    if not(cond(R)): return default

    if cond(L): return L

    R+=1
    while R-L>1:
        C=L+(R-L)//2
        if cond(C): R=C
        else: L=C
    return R
#=================================================
def cum(A,l,r):
    if l:
        return A[r]-A[l-1]
    else:
        return A[r]
#=================================================
def check(x):
    M=0
    for a in A:
        l=max(0,-a); r=min(P-1,x-a)
        if l<=r:
            M+=cum(B_cum,l,r)

        l=max(0,P-a); r=min(P-1,P+x-a)
        if l<=r:
            M+=cum(B_cum,l,r)
    return M>=K
#=================================================
N,K,P=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

B_cnt=[0]*P
for b in B:
    B_cnt[b]+=1

B_cum=[0]*(2*P); B_cum[0]=B[0]
for i in range(2*P):
    B_cum[i]=B_cum[i-1]+B_cnt[i%P]

print(General_Binary_Increase_Search_Integer(0,P-1,check))
0