結果
問題 | No.818 Dinner time |
ユーザー | LyricalMaestro |
提出日時 | 2024-09-15 01:02:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 323 ms / 2,000 ms |
コード長 | 1,572 bytes |
コンパイル時間 | 228 ms |
コンパイル使用メモリ | 82,160 KB |
実行使用メモリ | 93,988 KB |
最終ジャッジ日時 | 2024-09-15 01:02:08 |
合計ジャッジ時間 | 7,857 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,492 KB |
testcase_01 | AC | 42 ms
53,320 KB |
testcase_02 | AC | 38 ms
53,500 KB |
testcase_03 | AC | 39 ms
52,760 KB |
testcase_04 | AC | 41 ms
53,296 KB |
testcase_05 | AC | 39 ms
52,340 KB |
testcase_06 | AC | 37 ms
53,624 KB |
testcase_07 | AC | 38 ms
53,024 KB |
testcase_08 | AC | 39 ms
53,508 KB |
testcase_09 | AC | 40 ms
53,436 KB |
testcase_10 | AC | 39 ms
52,336 KB |
testcase_11 | AC | 38 ms
52,740 KB |
testcase_12 | AC | 51 ms
62,972 KB |
testcase_13 | AC | 56 ms
65,724 KB |
testcase_14 | AC | 54 ms
63,744 KB |
testcase_15 | AC | 53 ms
64,020 KB |
testcase_16 | AC | 51 ms
62,684 KB |
testcase_17 | AC | 310 ms
93,672 KB |
testcase_18 | AC | 243 ms
87,928 KB |
testcase_19 | AC | 247 ms
88,296 KB |
testcase_20 | AC | 303 ms
92,472 KB |
testcase_21 | AC | 298 ms
89,480 KB |
testcase_22 | AC | 238 ms
87,408 KB |
testcase_23 | AC | 258 ms
88,988 KB |
testcase_24 | AC | 323 ms
93,988 KB |
testcase_25 | AC | 259 ms
88,440 KB |
testcase_26 | AC | 234 ms
87,260 KB |
testcase_27 | AC | 296 ms
91,868 KB |
testcase_28 | AC | 262 ms
88,940 KB |
testcase_29 | AC | 316 ms
93,660 KB |
testcase_30 | AC | 311 ms
90,340 KB |
testcase_31 | AC | 299 ms
91,180 KB |
testcase_32 | AC | 264 ms
88,704 KB |
ソースコード
## https://yukicoder.me/problems/no/818 MIN_VALUE = -10**17 def main(): N, M = map(int, input().split()) ab = [] for _ in range(N): a, b = map(int, input().split()) ab.append((a, b)) if M == 1: array = [0] * N cum_ = 0 for i in range(N): a,b = ab[i] cum_ += max(a, b) array[i] = cum_ max_value = MIN_VALUE for i in range(N): max_value = max(max_value, array[i]) print(max_value) return dp = [[MIN_VALUE for _ in range(8)] for _ in range(N + 1)] dp[0][0] = 0 for i in range(N): a, b = ab[i] for state in range(8): for new_state in range(8): if new_state & state == state: x1 = 0 if state == 0: x1 = max(a * M, a * (M - 1) + b, b) elif state == 1: x1 = max(a * (M - 1), a * (M - 2) + b) elif state == 2: x1 = max(a * 2, a + b, b) elif state == 3: x1 = max(a , b) elif state == 4: x1 = max(a * (M - 1), b) elif state == 5: x1 = a * (M - 2) elif state == 6: x1 = max(a, b) dp[i +1][new_state] = max(dp[i + 1][new_state], dp[i][state] + x1) print(max(dp[-1])) if __name__ == "__main__": main()