結果
問題 |
No.1160 Strange Bowling
|
ユーザー |
![]() |
提出日時 | 2020-08-17 11:53:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 725 ms / 2,000 ms |
コード長 | 1,035 bytes |
コンパイル時間 | 2,496 ms |
コンパイル使用メモリ | 77,572 KB |
実行使用メモリ | 70,548 KB |
最終ジャッジ日時 | 2024-10-11 10:56:10 |
合計ジャッジ時間 | 20,650 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
import java.util.*; public class Main { static int[][] dp; static int[] pins; static int[] scores; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); pins = new int[n]; scores = new int[n]; for (int i = 0; i < n; i++) { pins[i] = sc.nextInt(); scores[i] = sc.nextInt(); } dp = new int[2][n]; System.out.println(dfw(n - 1, 0)); } static int dfw(int idx, int type) { if (idx < 0) { if (type == 1) { return Integer.MIN_VALUE; } else { return 0; } } if (dp[type][idx] == 0) { if (type == 0) { dp[type][idx] = Math.max(pins[idx] * 2 + dfw(idx - 1, 1), pins[idx] + dfw(idx - 1, 0)); } else { dp[type][idx] = Math.max(scores[idx] * 2 + dfw(idx - 1, 1), scores[idx] + dfw(idx - 1, 0)); } } return dp[type][idx]; } }