結果

問題 No.1211 円環はお断り
ユーザー vwxyzvwxyz
提出日時 2023-03-30 23:07:30
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,454 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,640 KB
実行使用メモリ 326,956 KB
最終ジャッジ日時 2023-10-22 06:37:12
合計ジャッジ時間 9,956 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
57,768 KB
testcase_01 AC 39 ms
53,420 KB
testcase_02 AC 39 ms
53,420 KB
testcase_03 AC 39 ms
53,420 KB
testcase_04 AC 38 ms
53,420 KB
testcase_05 AC 39 ms
53,420 KB
testcase_06 AC 39 ms
53,420 KB
testcase_07 AC 51 ms
61,816 KB
testcase_08 AC 39 ms
53,424 KB
testcase_09 AC 51 ms
63,876 KB
testcase_10 AC 54 ms
63,900 KB
testcase_11 AC 53 ms
63,900 KB
testcase_12 AC 44 ms
59,396 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

class Path_Doubling:
    def __init__(self,N,permutation,lst=None,f=None,e=None):
        self.N=N
        self.permutation=permutation
        self.lst=lst
        self.f=f
        self.e=e

    def Build_Next(self,K=None):
        if K==None:
            K=self.N
        self.k=K.bit_length()
        self.permutation_doubling=[[self.permutation[n]] for n in range(self.N)]
        if self.lst!=None:
            self.doubling=[[self.lst[n]] for n in range(self.N)]
        for k in range(1,self.k):
            for n in range(self.N):
                if self.permutation_doubling[n][k-1]==None:
                    self.permutation_doubling[n].append(None)
                    if self.f!=None:
                        self.doubling[n].append(None)
                if self.permutation_doubling[n][k-1]!=None:
                    self.permutation_doubling[n].append(self.permutation_doubling[self.permutation_doubling[n][k-1]][k-1])
                    if self.f!=None:
                        self.doubling[n].append(self.f(self.doubling[n][k-1],self.doubling[self.permutation_doubling[n][k-1]][k-1]))

    def Permutation_Doubling(self,N,K):
        if K<0 or 1<<self.k<=K:
            return None
        for k in range(self.k):
            if K>>k&1 and N!=None:
                N=self.permutation_doubling[N][k]
        return N

    def Doubling(self,N,K):
        if K<0:
            return self.e
        retu=self.e
        for k in range(self.k):
            if K>>k&1:
                if self.permutation_doubling[N][k]==None:
                    return None
                retu=self.f(retu,self.doubling[N][k])
                N=self.permutation_doubling[N][k]
        return retu

def Bisect_Int(ok,ng,is_ok):
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if is_ok(mid):
            ok=mid
        else:
            ng=mid
    return ok

N,K=map(int,readline().split())
A=list(map(int,readline().split()))
sum_A=sum(A)
A=[0]+A*2
for i in range(1,2*N+1):
    A[i]+=A[i-1]
def is_ok(ans):
    perm=[i for i in range(2*N+1)]
    r=0
    for l in range(2*N):
        while r<2*N and A[r]-A[l]<ans:
            r+=1
        perm[l]=r
    PD=Path_Doubling(2*N+1,perm)
    PD.Build_Next(K)
    for i in range(N):
        x=PD.Permutation_Doubling(i,K)
        if ans<A[i]:
            break
        if x<=i+N:
            return True
    return False
ans=Bisect_Int(0,sum_A//K+1,is_ok)
print(ans)
0