結果

問題 No.1935 Water Simulation
ユーザー ああ
提出日時 2022-12-28 12:19:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 768 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 59,648 KB
最終ジャッジ日時 2024-11-23 12:44:05
合計ジャッジ時間 2,821 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
V1,V2,V3,V4,N=map(int,input().split())

youseki=[V1,V2,V3,V4]
V=[V1,0,0,0]
link=[(V1,0,0,0,0)]
s=set()
s.add((V1,0,0,0,0))
index=0
d=defaultdict(int)
d[(V1,0,0,0,0)]=index
check=True
while(check):
    for i in range(4):
        if youseki[(i+1)%4]-V[(i+1)%4]<=V[i]:
            V[i]-=youseki[(i+1)%4]-V[(i+1)%4]
            V[(i+1)%4]=youseki[(i+1)%4]
        else:
            V[(i+1)%4]+=V[i]
            V[i]=0
        index+=1
        tplV=tuple([V[0],V[1],V[2],V[3],index%4])
        if tplV in s:
            check=False
            break
        s.add(tplV)
        link.append(tplV)
        d[tplV]=index

lastV=tplV
if index>N:
    print(*link[N][:4])
else:
    N-=d[lastV]
    print(*link[d[lastV]+N%(index-d[lastV])][:4])
0