結果
問題 | No.664 超能力者Aと株価予測 |
ユーザー | htensai |
提出日時 | 2020-02-06 17:18:15 |
言語 | Java19 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,822 bytes |
コンパイル時間 | 4,149 ms |
コンパイル使用メモリ | 77,084 KB |
実行使用メモリ | 53,256 KB |
最終ジャッジ日時 | 2023-10-25 22:36:20 |
合計ジャッジ時間 | 3,835 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
53,228 KB |
testcase_01 | AC | 51 ms
53,220 KB |
testcase_02 | AC | 50 ms
53,256 KB |
testcase_03 | AC | 50 ms
53,220 KB |
testcase_04 | AC | 49 ms
53,220 KB |
testcase_05 | AC | 49 ms
53,232 KB |
testcase_06 | AC | 49 ms
53,228 KB |
testcase_07 | AC | 49 ms
53,224 KB |
testcase_08 | AC | 50 ms
53,236 KB |
testcase_09 | WA | - |
testcase_10 | AC | 52 ms
53,228 KB |
testcase_11 | AC | 52 ms
53,236 KB |
testcase_12 | AC | 53 ms
53,228 KB |
testcase_13 | AC | 52 ms
53,240 KB |
testcase_14 | AC | 49 ms
53,224 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 3); int n = Integer.parseInt(first[0]); int m = Integer.parseInt(first[1]); int k = Integer.parseInt(first[2]); int[] prices = new int[n + 2]; for (int i = 1; i <= n + 1; i++) { prices[i] = Integer.parseInt(br.readLine()); } int[][] buyDp = new int[m + 1][n + 2]; int[][] sellDp = new int[m + 1][n + 2]; int[][] restDp = new int[m + 1][n + 2]; Arrays.fill(sellDp[0], k); for (int i = 1; i <= m; i++) { for (int j = 1; j <= n + 1; j++) { int buy = sellDp[i - 1][j - 1] / prices[j]; int rest = sellDp[i - 1][j - 1] % prices[j]; if (buy == buyDp[i - 1][j]) { rest = Math.max(rest, restDp[i - 1][j]); } else if (buy < buyDp[i - 1][j]) { buy = buyDp[i - 1][j]; rest = restDp[i - 1][j]; } if (buy == buyDp[i][j - 1]) { rest = Math.max(rest, restDp[i][j - 1]); } else if (buy < buyDp[i][j - 1]) { buy = buyDp[i][j - 1]; rest = restDp[i][j - 1]; } buyDp[i][j] = buy; restDp[i][j] = rest; } for (int j = 1; j <= n + 1; j++) { sellDp[i][j] = Math.max(Math.max(sellDp[i - 1][j], sellDp[i][j - 1]), Math.max(sellDp[i][j], buyDp[i][j - 1] * prices[j] + restDp[i][j - 1])); } } System.out.println(sellDp[m][n + 1]); } }