結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,368 KB
testcase_01 AC 34 ms
53,368 KB
testcase_02 AC 34 ms
53,368 KB
testcase_03 AC 51 ms
65,856 KB
testcase_04 AC 45 ms
61,680 KB
testcase_05 AC 52 ms
65,868 KB
testcase_06 AC 50 ms
63,720 KB
testcase_07 AC 55 ms
65,868 KB
testcase_08 AC 52 ms
65,844 KB
testcase_09 AC 55 ms
65,908 KB
testcase_10 AC 55 ms
65,916 KB
testcase_11 AC 52 ms
65,916 KB
testcase_12 AC 56 ms
68,016 KB
testcase_13 AC 81 ms
78,000 KB
testcase_14 AC 229 ms
103,464 KB
testcase_15 AC 322 ms
106,756 KB
testcase_16 AC 336 ms
124,080 KB
testcase_17 AC 185 ms
93,596 KB
testcase_18 AC 251 ms
106,200 KB
testcase_19 AC 144 ms
89,064 KB
testcase_20 AC 395 ms
117,700 KB
testcase_21 AC 187 ms
97,544 KB
testcase_22 AC 236 ms
97,436 KB
testcase_23 AC 110 ms
81,608 KB
testcase_24 AC 486 ms
147,096 KB
testcase_25 AC 445 ms
118,072 KB
testcase_26 AC 118 ms
85,524 KB
testcase_27 AC 161 ms
91,968 KB
testcase_28 AC 115 ms
81,748 KB
testcase_29 AC 418 ms
116,084 KB
testcase_30 AC 176 ms
95,112 KB
testcase_31 AC 302 ms
115,692 KB
testcase_32 AC 205 ms
101,704 KB
testcase_33 AC 334 ms
147,372 KB
testcase_34 AC 579 ms
202,696 KB
testcase_35 AC 605 ms
194,372 KB
testcase_36 AC 95 ms
80,028 KB
testcase_37 AC 91 ms
79,836 KB
testcase_38 AC 632 ms
217,424 KB
testcase_39 AC 215 ms
110,236 KB
testcase_40 AC 683 ms
202,008 KB
testcase_41 AC 158 ms
93,832 KB
testcase_42 AC 317 ms
143,580 KB
testcase_43 AC 199 ms
97,012 KB
testcase_44 AC 334 ms
148,584 KB
testcase_45 AC 287 ms
136,672 KB
testcase_46 AC 177 ms
96,192 KB
testcase_47 AC 276 ms
119,196 KB
testcase_48 AC 379 ms
159,568 KB
testcase_49 AC 600 ms
201,244 KB
testcase_50 AC 474 ms
179,264 KB
testcase_51 AC 405 ms
166,336 KB
testcase_52 AC 120 ms
88,468 KB
testcase_53 AC 142 ms
92,228 KB
testcase_54 AC 459 ms
193,772 KB
testcase_55 AC 176 ms
97,664 KB
testcase_56 AC 728 ms
229,736 KB
testcase_57 AC 786 ms
174,208 KB
testcase_58 AC 1,060 ms
255,776 KB
testcase_59 AC 934 ms
255,844 KB
testcase_60 AC 734 ms
255,624 KB
testcase_61 AC 372 ms
120,620 KB
testcase_62 AC 142 ms
98,288 KB
testcase_63 AC 39 ms
53,388 KB
testcase_64 AC 35 ms
53,388 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=PD.Permutation_Doubling(i,K)
    _,d=PD.Doubling(i,K)
    ans=pd+d*N+1
    print(ans)
0