結果

問題 No.1597 Matrix Sort
ユーザー 👑 KazunKazun
提出日時 2021-07-09 21:58:42
言語 PyPy3
(7.9.16)
結果
AC  
実行時間 606 ms / 1,500 ms
コード長 1,233 bytes
コンパイル時間 269 ms
実行使用メモリ 329,728 KB
最終ジャッジ日時 2023-02-01 23:22:05
合計ジャッジ時間 12,449 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
75,748 KB
testcase_01 AC 86 ms
80,696 KB
testcase_02 AC 84 ms
80,692 KB
testcase_03 AC 411 ms
328,672 KB
testcase_04 AC 606 ms
329,040 KB
testcase_05 AC 504 ms
329,116 KB
testcase_06 AC 497 ms
329,588 KB
testcase_07 AC 477 ms
329,492 KB
testcase_08 AC 524 ms
329,364 KB
testcase_09 AC 455 ms
329,620 KB
testcase_10 AC 398 ms
325,504 KB
testcase_11 AC 417 ms
329,576 KB
testcase_12 AC 166 ms
104,540 KB
testcase_13 AC 237 ms
119,236 KB
testcase_14 AC 537 ms
329,604 KB
testcase_15 AC 168 ms
104,440 KB
testcase_16 AC 206 ms
118,592 KB
testcase_17 AC 454 ms
328,864 KB
testcase_18 AC 527 ms
329,728 KB
testcase_19 AC 490 ms
329,576 KB
testcase_20 AC 447 ms
328,972 KB
testcase_21 AC 441 ms
328,400 KB
testcase_22 AC 441 ms
328,160 KB
testcase_23 AC 447 ms
325,928 KB
testcase_24 AC 136 ms
106,316 KB
testcase_25 AC 125 ms
106,452 KB
testcase_26 AC 83 ms
75,568 KB
testcase_27 AC 83 ms
75,572 KB
testcase_28 AC 83 ms
75,572 KB
testcase_29 AC 311 ms
315,060 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