結果
問題 | No.1935 Water Simulation |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:12:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 2,606 bytes |
コンパイル時間 | 486 ms |
コンパイル使用メモリ | 82,360 KB |
実行使用メモリ | 59,980 KB |
最終ジャッジ日時 | 2025-03-20 21:14:09 |
合計ジャッジ時間 | 2,756 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
V1, V2, V3, V4, N = map(int, input().split())v = [V1, V2, V3, V4]a = [v[0], 0, 0, 0]current_step = 0next_op = 1 # after 0 steps, the first operation is 1state_map = {}state_key = (tuple(a), next_op)state_map[state_key] = current_stepfound_cycle = Falsewhile current_step < N:# Perform the current operationcurrent_op = next_opif current_op == 1:# Pour from 1 to 2 (indices 0 to 1)transfer = min(a[0], v[1] - a[1])a[0] -= transfera[1] += transferelif current_op == 2:# Pour from 2 to 3 (indices 1 to 2)transfer = min(a[1], v[2] - a[2])a[1] -= transfera[2] += transferelif current_op == 3:# Pour from 3 to 4 (indices 2 to 3)transfer = min(a[2], v[3] - a[3])a[2] -= transfera[3] += transferelse:# Pour from 4 to 1 (indices 3 to 0)transfer = min(a[3], v[0] - a[0])a[3] -= transfera[0] += transfercurrent_step += 1if current_step == N:break# Determine next_op for the next stepnext_op = (current_step % 4) + 1new_key = (tuple(a), next_op)# Check for cycleif new_key in state_map:prev_step = state_map[new_key]cycle_len = current_step - prev_stepremaining_steps = N - current_stepcycles = remaining_steps // cycle_lencurrent_step += cycles * cycle_len# Update to the state that started the cyclea = list(new_key[0])next_op = new_key[1]# Handle remaining steps after cyclesif current_step < N:steps_rem = N - current_stepfor _ in range(steps_rem):curr_op = next_opif curr_op == 1:transfer = min(a[0], v[1] - a[1])a[0] -= transfera[1] += transferelif curr_op == 2:transfer = min(a[1], v[2] - a[2])a[1] -= transfera[2] += transferelif curr_op == 3:transfer = min(a[2], v[3] - a[3])a[2] -= transfera[3] += transferelse:transfer = min(a[3], v[0] - a[0])a[3] -= transfera[0] += transfercurrent_step += 1if current_step >= N:breaknext_op = (current_step % 4) + 1breakelse:state_map[new_key] = current_stepprint(' '.join(map(str, a)))