結果

問題 No.1935 Water Simulation
ユーザー vwxyz
提出日時 2024-06-02 05:08:05
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,628 ms / 2,000 ms
コード長 1,205 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 102,500 KB
最終ジャッジ日時 2024-12-22 22:40:10
合計ジャッジ時間 13,107 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

def Permutation_Product(x,n,f):
    lst=[]
    dct={}
    idx=0
    cur=x
    while True:
        if cur in dct.keys():
            loop_begin=dct[cur]
            loop_end=idx
            break
        else:
            lst.append(cur)
            dct[cur]=idx
            cur=f(cur)
            idx+=1
    if loop_end-1>=n:
        return lst[n]
    n-=loop_begin
    loop_length=loop_end-loop_begin
    lst=lst[loop_begin:]
    return lst[n%(loop_length)]

A,B,C,D,N=map(int,input().split())
V=A
ABCDE=[]
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            d=V-a-b-c
            if 0<=d<=D:
                for e in range(4):
                    ABCDE.append((a,b,c,d,e))
idx={ABCDE[i]:i for i in range(len(ABCDE))}
le=len(ABCDE)
perm=[None]*le
for i,(a,b,c,d,e) in enumerate(ABCDE):
    if e==0:
        x=min(B-b,a)
        a-=x
        b+=x
    elif e==1:
        x=min(C-c,b)
        b-=x
        c+=x
    elif e==2:
        x=min(D-d,c)
        c-=x
        d+=x
    elif e==3:
        x=min(A-a,d)
        d-=x
        a+=x
    e+=1
    e%=4
    perm[i]=idx[(a,b,c,d,e)]
A,B,C,D,E=ABCDE[Permutation_Product(idx[(A,0,0,0,0)],N,f=lambda i:perm[i])]
print(A,B,C,D)
0