結果

問題 No.1013 〇マス進む
ユーザー vwxyzvwxyz
提出日時 2023-03-31 10:52:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 2,378 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 12,192 KB
実行使用メモリ 116,912 KB
最終ジャッジ日時 2023-10-23 22:51:49
合計ジャッジ時間 34,823 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,316 KB
testcase_01 AC 29 ms
10,316 KB
testcase_02 AC 28 ms
10,316 KB
testcase_03 AC 33 ms
10,504 KB
testcase_04 AC 30 ms
10,384 KB
testcase_05 AC 33 ms
10,536 KB
testcase_06 AC 32 ms
10,464 KB
testcase_07 AC 36 ms
10,688 KB
testcase_08 AC 34 ms
10,576 KB
testcase_09 AC 35 ms
10,676 KB
testcase_10 AC 33 ms
10,584 KB
testcase_11 AC 33 ms
10,508 KB
testcase_12 AC 35 ms
10,660 KB
testcase_13 AC 69 ms
12,028 KB
testcase_14 AC 750 ms
33,228 KB
testcase_15 AC 1,344 ms
47,336 KB
testcase_16 AC 1,241 ms
45,356 KB
testcase_17 AC 594 ms
30,120 KB
testcase_18 AC 867 ms
35,464 KB
testcase_19 AC 382 ms
21,024 KB
testcase_20 AC 1,399 ms
43,624 KB
testcase_21 AC 568 ms
29,268 KB
testcase_22 AC 864 ms
35,620 KB
testcase_23 AC 212 ms
18,468 KB
testcase_24 AC 1,816 ms
58,208 KB
testcase_25 AC 1,686 ms
56,128 KB
testcase_26 AC 256 ms
19,004 KB
testcase_27 AC 483 ms
27,456 KB
testcase_28 AC 197 ms
16,484 KB
testcase_29 AC 1,471 ms
43,152 KB
testcase_30 AC 508 ms
26,492 KB
testcase_31 AC 1,068 ms
40,216 KB
testcase_32 AC 665 ms
33,016 KB
testcase_33 AC 1,613 ms
73,408 KB
testcase_34 TLE -
testcase_35 TLE -
testcase_36 AC 163 ms
16,776 KB
testcase_37 AC 153 ms
16,608 KB
testcase_38 TLE -
testcase_39 AC 946 ms
43,872 KB
testcase_40 TLE -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
権限があれば一括ダウンロードができます

ソースコード

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:
            self.K=self.N
        else:
            self.K=K
        self.k=self.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(self,x,is_ok):
        if not is_ok(x):
            return -1,None
        K=0
        for k in range(self.k-1,-1,-1):
            if K|1<<k<=self.K and is_ok(self.permutation_doubling[x][k]):
                K|=1<<k
                x=self.permutation_doubling[x][k]
        return K,x

N,K=map(int,readline().split())
P=list(map(int,readline().split()))
PD=Path_Doubling(N,[(P[i]+i)%N for i in range(N)],[(i+P[i])//N for i in range(N)],lambda x,y:x+y,0)
PD.Build_Next(K)
for i in range(N):
    pd=PD.Permutation_Doubling(i,K)
    d=PD.Doubling(i,K)
    ans=pd+d*N+1
    print(ans)
0