結果

問題 No.2057 Ising Model
ユーザー FromBooskaFromBooska
提出日時 2023-06-09 14:55:26
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 678 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 841,104 KB
最終ジャッジ日時 2023-08-30 08:55:35
合計ジャッジ時間 6,098 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,536 KB
testcase_01 AC 68 ms
71,380 KB
testcase_02 AC 70 ms
71,112 KB
testcase_03 AC 68 ms
71,544 KB
testcase_04 AC 69 ms
71,536 KB
testcase_05 AC 70 ms
71,448 KB
testcase_06 AC 70 ms
71,336 KB
testcase_07 AC 70 ms
71,544 KB
testcase_08 AC 70 ms
71,268 KB
testcase_09 AC 69 ms
71,104 KB
testcase_10 AC 69 ms
71,228 KB
testcase_11 AC 71 ms
71,204 KB
testcase_12 AC 70 ms
71,372 KB
testcase_13 AC 69 ms
71,328 KB
testcase_14 AC 69 ms
71,084 KB
testcase_15 AC 69 ms
71,540 KB
testcase_16 AC 70 ms
71,336 KB
testcase_17 AC 69 ms
71,272 KB
testcase_18 AC 69 ms
71,388 KB
testcase_19 AC 68 ms
71,380 KB
testcase_20 AC 68 ms
71,348 KB
testcase_21 AC 69 ms
71,508 KB
testcase_22 AC 69 ms
71,332 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 MLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 2次元dpでできる
# dp[i個目まで見て][i個目が+1のとき0、i個目が-1のとき1]の最小値

N, A, B = map(int, input().split())

INF = 10**20
dp = [[INF]*2 for i in range(N+1)]
dp[0][0] = 0
dp[0][1] = 0

for i in range(1, N+1):
    if i == 1:
        # +1のとき
        dp[i][0] = min(dp[i][0], dp[i-1][0]-B, dp[i-1][1]-B)
        # -1のとき
        dp[i][1] = min(dp[i][1], dp[i-1][0]+B, dp[i-1][1]+B)        
    elif i > 1:
        # +1のとき
        dp[i][0] = min(dp[i][0], dp[i-1][0]+A-B, dp[i-1][1]-A-B)
        # -1のとき
        dp[i][1] = min(dp[i][1], dp[i-1][0]-A+B, dp[i-1][1]+A+B)
    
    #print(dp[i])

ans = min(dp[N])
print(ans)
0