結果

問題 No.1935 Water Simulation
ユーザー LyricalMaestroLyricalMaestro
提出日時 2024-02-25 00:21:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,460 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 166,616 KB
最終ジャッジ日時 2024-02-25 00:21:48
合計ジャッジ時間 4,734 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 87 ms
80,568 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 142 ms
108,576 KB
testcase_09 AC 225 ms
147,700 KB
testcase_10 AC 221 ms
137,316 KB
testcase_11 WA -
testcase_12 AC 43 ms
59,324 KB
testcase_13 AC 42 ms
59,064 KB
testcase_14 AC 72 ms
78,292 KB
testcase_15 AC 135 ms
101,852 KB
testcase_16 AC 134 ms
108,648 KB
testcase_17 WA -
testcase_18 AC 39 ms
59,064 KB
testcase_19 AC 188 ms
120,544 KB
testcase_20 AC 52 ms
66,264 KB
testcase_21 WA -
testcase_22 AC 120 ms
93,616 KB
testcase_23 AC 72 ms
78,184 KB
testcase_24 AC 275 ms
166,616 KB
testcase_25 WA -
testcase_26 AC 47 ms
61,432 KB
testcase_27 AC 96 ms
89,304 KB
testcase_28 AC 77 ms
78,840 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1935


def main():
    V1, V2, V3, V4, N = map(int, input().split())

    state_array = []
    for v1 in range(V1 + 1):
        for v2 in range(V2 + 1):
            for v3 in range(V3 + 1):
                if V1 < v1 + v2 + v3:
                    break

                v4 = V1 - v1 - v2 - v3
                if v4 > V4:
                    continue

                state_array.append((v1, v2, v3, v4))
    state_map = {}
    state_max = len(state_array)
    for i, state in enumerate(state_array):
        state_map[state] = i

    func_map = [-1] * state_max
    for i, state in enumerate(state_array):
        v1, v2, v3, v4 = state

        # 操作1を実施
        new_v1 = v1 - min(v1, V2 - v2)
        new_v2 = v2 + min(v1, V2 - v2)
        v1 = new_v1
        v2 = new_v2

        # 操作2を実施
        new_v2 = v2 - min(v2, V3 - v3)
        new_v3 = v3 + min(v2, V3 - v3)
        v2 = new_v2
        v3 = new_v3

        # 操作3を実施
        new_v3 = v3 - min(v3, V4 - v4)
        new_v4 = v4 + min(v3, V4 - v4)
        v3 = new_v3
        v4 = new_v4

        # 操作4を実施
        new_v4 = v4 - min(v4, V1 - v1)
        new_v1 = v1 + min(v4, V1 - v1)
        v4 = new_v4
        v1 = new_v1

        func_map[state_map[(v1, v2, v3, v4)]] = i

    n0 = N // 4
    # ダブリングを実施
    state = state_map[(V1, 0, 0, 0)]
    while n0 > 0:
        if n0 % 2 == 1:
            state = func_map[state]
        
        func_map = [func_map[func_map[s]] for s in range(state_max)]
        n0 //= 2

    n1 = N - (N // 4) * 4
    if n1 > 0:
        v1, v2, v3, v4 = state_array[state]
    
        # 操作1を実施
        new_v1 = v1 - min(v1, V2 - v2)
        new_v2 = v2 + min(v1, V2 - v2)
        v1 = new_v1
        v2 = new_v2
        if n1 == 1:
            print(v1, v2, v3, v4)
            return

        # 操作2を実施
        new_v2 = v2 - min(v2, V3 - v3)
        new_v3 = v3 + min(v2, V3 - v3)
        v2 = new_v2
        v3 = new_v3
        if n1 == 2:
            print(v1, v2, v3, v4)
            return

        # 操作3を実施
        new_v3 = v3 - min(v3, V4 - v4)
        new_v4 = v4 + min(v3, V4 - v4)
        v3 = new_v3
        v4 = new_v4
        if n1 == 3:
            print(v1, v2, v3, v4)
            return
    else:
        v1, v2, v3, v4 = state_array[state]
        print(v1, v2, v3, v4)
        return










if __name__ == "__main__":
    main()
0