class CycleGetter(): def __init__(self,start,max_time): """ :param max_time: 移動回数 :param start: 初期条件 :return front: cycleまでの要素のリスト cycle: cycle内の要素のリスト end: cycle後の余った部分の要素のリスト cnt: cycle回数 """ p = start front, cycle, end = [], [], [] max_time+=1 cnt = 0 visit = {p:0} L, R =max_time,-1 P = [p] for i in range(1,max_time): p = lift(p) if p in visit: """ (L, R) = (サイクルに入るまでに移動した回数, サイクルの終端に着くまでに移動した回数) [6,2,3,4,0,1,2] ⇒ (L, R) = (1, 6) """ L, R = visit[p], i period = R-L break visit[p] = i P.append(p) front = P[:L] if L != max_time: cycle, end = P[L:R],P[L:L+(max_time-L)%period] cnt =(max_time-L)//period self.front,self.cycle,self.end,self.cnt = front, cycle, end, cnt def apply(self,time): """ :param time: time回進む :return: """ if time