結果

問題 No.1013 〇マス進む
ユーザー vwxyzvwxyz
提出日時 2023-03-31 10:55:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 922 ms / 2,000 ms
コード長 1,725 bytes
コンパイル時間 2,349 ms
コンパイル使用メモリ 81,412 KB
実行使用メモリ 255,672 KB
最終ジャッジ日時 2023-10-23 22:56:22
合計ジャッジ時間 19,923 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,360 KB
testcase_01 AC 34 ms
53,360 KB
testcase_02 AC 35 ms
53,360 KB
testcase_03 AC 50 ms
63,892 KB
testcase_04 AC 43 ms
61,792 KB
testcase_05 AC 49 ms
63,880 KB
testcase_06 AC 48 ms
63,804 KB
testcase_07 AC 52 ms
65,928 KB
testcase_08 AC 50 ms
63,864 KB
testcase_09 AC 52 ms
65,980 KB
testcase_10 AC 51 ms
63,880 KB
testcase_11 AC 48 ms
63,880 KB
testcase_12 AC 51 ms
65,980 KB
testcase_13 AC 83 ms
77,716 KB
testcase_14 AC 194 ms
103,300 KB
testcase_15 AC 293 ms
106,588 KB
testcase_16 AC 291 ms
123,832 KB
testcase_17 AC 160 ms
93,436 KB
testcase_18 AC 226 ms
106,060 KB
testcase_19 AC 128 ms
88,940 KB
testcase_20 AC 333 ms
117,072 KB
testcase_21 AC 160 ms
97,364 KB
testcase_22 AC 210 ms
97,108 KB
testcase_23 AC 97 ms
81,460 KB
testcase_24 AC 402 ms
146,932 KB
testcase_25 AC 350 ms
117,836 KB
testcase_26 AC 107 ms
85,420 KB
testcase_27 AC 138 ms
91,840 KB
testcase_28 AC 98 ms
81,564 KB
testcase_29 AC 317 ms
115,852 KB
testcase_30 AC 148 ms
94,816 KB
testcase_31 AC 264 ms
115,260 KB
testcase_32 AC 187 ms
101,552 KB
testcase_33 AC 309 ms
147,224 KB
testcase_34 AC 512 ms
202,508 KB
testcase_35 AC 548 ms
194,224 KB
testcase_36 AC 86 ms
79,832 KB
testcase_37 AC 86 ms
79,616 KB
testcase_38 AC 564 ms
217,288 KB
testcase_39 AC 184 ms
109,760 KB
testcase_40 AC 588 ms
201,836 KB
testcase_41 AC 137 ms
93,580 KB
testcase_42 AC 279 ms
143,508 KB
testcase_43 AC 175 ms
96,892 KB
testcase_44 AC 292 ms
148,428 KB
testcase_45 AC 250 ms
136,692 KB
testcase_46 AC 146 ms
96,044 KB
testcase_47 AC 240 ms
119,056 KB
testcase_48 AC 335 ms
159,072 KB
testcase_49 AC 530 ms
201,140 KB
testcase_50 AC 414 ms
179,108 KB
testcase_51 AC 357 ms
166,196 KB
testcase_52 AC 109 ms
88,356 KB
testcase_53 AC 126 ms
92,044 KB
testcase_54 AC 408 ms
193,536 KB
testcase_55 AC 162 ms
97,552 KB
testcase_56 AC 600 ms
230,000 KB
testcase_57 AC 454 ms
174,052 KB
testcase_58 AC 907 ms
255,648 KB
testcase_59 AC 922 ms
255,620 KB
testcase_60 AC 685 ms
255,672 KB
testcase_61 AC 314 ms
120,132 KB
testcase_62 AC 121 ms
98,256 KB
testcase_63 AC 35 ms
53,360 KB
testcase_64 AC 34 ms
53,360 KB
権限があれば一括ダウンロードができます

ソースコード

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):
        self.K=K
        self.k=self.K.bit_length()
        self.permutation_doubling=[[self.permutation[n]] for n in range(self.N)]
        self.doubling=[[self.lst[n]] for n in range(self.N)]
        for k in range(1,self.k):
            for n in range(self.N):
                self.permutation_doubling[n].append(self.permutation_doubling[self.permutation_doubling[n][k-1]][k-1])
                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):
        for k in range(self.k):
            if K>>k&1:
                N=self.permutation_doubling[N][k]
        return N

    def Doubling(self,N,K):
        retu=self.e
        for k in range(self.k):
            if K>>k&1:
                retu=self.f(retu,self.doubling[N][k])
                N=self.permutation_doubling[N][k]
        return N,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,d=PD.Doubling(i,K)
    ans=pd+d*N+1
    print(ans)
0