結果

問題 No.2057 Ising Model
ユーザー FromBooskaFromBooska
提出日時 2023-06-09 19:31:43
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,193 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 831,192 KB
最終ジャッジ日時 2023-08-30 11:43:18
合計ジャッジ時間 8,250 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,336 KB
testcase_01 AC 73 ms
71,436 KB
testcase_02 AC 75 ms
71,232 KB
testcase_03 AC 74 ms
71,280 KB
testcase_04 AC 74 ms
71,080 KB
testcase_05 AC 74 ms
71,240 KB
testcase_06 AC 75 ms
71,336 KB
testcase_07 AC 74 ms
71,332 KB
testcase_08 AC 74 ms
71,468 KB
testcase_09 AC 74 ms
71,428 KB
testcase_10 AC 74 ms
71,340 KB
testcase_11 AC 74 ms
71,124 KB
testcase_12 AC 75 ms
71,340 KB
testcase_13 AC 75 ms
71,388 KB
testcase_14 AC 72 ms
71,500 KB
testcase_15 AC 74 ms
71,336 KB
testcase_16 AC 76 ms
71,248 KB
testcase_17 AC 76 ms
71,224 KB
testcase_18 AC 77 ms
71,224 KB
testcase_19 AC 76 ms
71,340 KB
testcase_20 AC 74 ms
71,332 KB
testcase_21 AC 74 ms
71,332 KB
testcase_22 AC 76 ms
71,084 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 #

# 10**10なので2次元dpだとRE出るのでdpを前半後半に分けてみよう
# dp[i個目まで見て][i個目が+1のとき0、i個目が-1のとき1]の最小値
# dp1 for N1 (前半), dp2 for N2

N, A, B = map(int, input().split())
N1 = N//2
N2 = N - N1

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

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

dp2 = [[INF]*2 for i in range(N2+1)]
dp2[0][0] = dp1[N1][0]
dp2[0][1] = dp1[N1][1]

for i in range(1, N2+1): 
    # dp2では第1項だけ異なるというのがない
    # +1のとき
    dp2[i][0] = min(dp2[i][0], dp2[i-1][0]+A-B, dp2[i-1][1]-A-B)
    # -1のとき
    dp2[i][1] = min(dp2[i][1], dp2[i-1][0]-A+B, dp2[i-1][1]+A+B)
    #print('dp2[i]', dp2[i])
    
ans = min(dp2[N2])
print(ans)
0