結果

問題 No.1597 Matrix Sort
ユーザー 👑 KazunKazun
提出日時 2021-07-09 21:58:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 566 ms / 1,500 ms
コード長 1,233 bytes
コンパイル時間 341 ms
コンパイル使用メモリ 82,328 KB
実行使用メモリ 322,240 KB
最終ジャッジ日時 2024-07-01 16:18:10
合計ジャッジ時間 10,734 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,352 KB
testcase_01 AC 44 ms
58,112 KB
testcase_02 AC 44 ms
57,984 KB
testcase_03 AC 338 ms
319,852 KB
testcase_04 AC 565 ms
319,516 KB
testcase_05 AC 469 ms
319,772 KB
testcase_06 AC 465 ms
319,520 KB
testcase_07 AC 451 ms
319,652 KB
testcase_08 AC 566 ms
319,704 KB
testcase_09 AC 448 ms
319,476 KB
testcase_10 AC 342 ms
322,012 KB
testcase_11 AC 370 ms
319,888 KB
testcase_12 AC 134 ms
102,784 KB
testcase_13 AC 232 ms
126,720 KB
testcase_14 AC 557 ms
320,024 KB
testcase_15 AC 136 ms
102,688 KB
testcase_16 AC 176 ms
126,464 KB
testcase_17 AC 457 ms
319,756 KB
testcase_18 AC 547 ms
319,512 KB
testcase_19 AC 427 ms
319,508 KB
testcase_20 AC 387 ms
319,472 KB
testcase_21 AC 380 ms
320,116 KB
testcase_22 AC 382 ms
322,240 KB
testcase_23 AC 390 ms
322,028 KB
testcase_24 AC 106 ms
100,864 KB
testcase_25 AC 87 ms
99,200 KB
testcase_26 AC 40 ms
52,204 KB
testcase_27 AC 39 ms
52,224 KB
testcase_28 AC 40 ms
52,608 KB
testcase_29 AC 238 ms
291,968 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