結果

問題 No.1935 Water Simulation
ユーザー 炭酸水炭酸水
提出日時 2022-05-13 22:28:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,392 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 10,780 KB
実行使用メモリ 8,240 KB
最終ジャッジ日時 2023-09-29 07:56:18
合計ジャッジ時間 2,053 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 16 ms
8,052 KB
testcase_05 AC 17 ms
8,064 KB
testcase_06 AC 17 ms
8,048 KB
testcase_07 AC 17 ms
8,036 KB
testcase_08 AC 18 ms
8,192 KB
testcase_09 AC 17 ms
8,056 KB
testcase_10 AC 17 ms
8,052 KB
testcase_11 AC 16 ms
8,096 KB
testcase_12 AC 17 ms
8,048 KB
testcase_13 AC 17 ms
8,048 KB
testcase_14 AC 17 ms
8,092 KB
testcase_15 AC 17 ms
8,052 KB
testcase_16 AC 16 ms
7,976 KB
testcase_17 AC 16 ms
7,976 KB
testcase_18 AC 17 ms
7,984 KB
testcase_19 AC 16 ms
8,240 KB
testcase_20 AC 16 ms
8,048 KB
testcase_21 AC 17 ms
8,180 KB
testcase_22 AC 16 ms
8,048 KB
testcase_23 AC 16 ms
8,224 KB
testcase_24 AC 17 ms
8,052 KB
testcase_25 AC 16 ms
8,044 KB
testcase_26 AC 16 ms
7,980 KB
testcase_27 AC 16 ms
8,112 KB
testcase_28 AC 17 ms
8,064 KB
testcase_29 AC 16 ms
8,124 KB
testcase_30 AC 17 ms
7,980 KB
testcase_31 AC 17 ms
8,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

a, b, c, d, n = map(int, input().split())
s = [a, b, c, d]

dp = [a, 0, 0, 0]
s_0 = []
s_1 = set()

j = 0
sw = True
while sw:
    s_0.append(dp.copy())
    s_1.add(tuple(dp))
    
    if dp[j % 4] + dp[(j + 1) % 4] <= s[(j + 1) % 4]:
        dp[j % 4], dp[(j + 1) % 4] = 0, dp[j % 4] + dp[(j + 1) % 4]
    else:
        dp[j % 4], dp[(j + 1) % 4] = dp[j % 4] + dp[(j + 1) % 4] - s[(j + 1) % 4], s[(j + 1) % 4]    
    j += 1
    if tuple(dp) in s_1:
        for i in range(len(s_0)):
            if dp == s_0[i]:
                loop_dp = dp
                loop = 17
                loop_T = j - i
        sw = False

if n <= loop:

    dp = [a, 0, 0, 0]    
    j = 0
    while j < n:
        if dp[j % 4] + dp[(j + 1) % 4] <= s[(j + 1) % 4]:
            dp[j % 4], dp[(j + 1) % 4] = 0, dp[j % 4] + dp[(j + 1) % 4]
        else:
            dp[j % 4], dp[(j + 1) % 4] = dp[j % 4] + dp[(j + 1) % 4] - s[(j + 1) % 4], s[(j + 1) % 4]    
        j += 1    
    
    print(*dp)
    
    
else:
    m = (n - loop) // loop_T
    k = n - loop - loop_T * m
    
    dp = loop_dp
    
    j = 0
    while j <= k:
        if dp[j % 4] + dp[(j + 1) % 4] <= s[(j + 1) % 4]:
            dp[j % 4], dp[(j + 1) % 4] = 0, dp[j % 4] + dp[(j + 1) % 4]
        else:
            dp[j % 4], dp[(j + 1) % 4] = dp[j % 4] + dp[(j + 1) % 4] - s[(j + 1) % 4], s[(j + 1) % 4]    
        j += 1
    
    print(*dp)

0