結果
問題 | No.258 回転寿司(2) |
ユーザー | tenten |
提出日時 | 2021-11-10 21:21:46 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,706 bytes |
コンパイル時間 | 2,577 ms |
コンパイル使用メモリ | 78,648 KB |
実行使用メモリ | 48,764 KB |
最終ジャッジ日時 | 2024-11-21 13:21:54 |
合計ジャッジ時間 | 10,368 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 54 ms
36,936 KB |
testcase_05 | AC | 58 ms
37,032 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 56 ms
36,628 KB |
testcase_09 | WA | - |
testcase_10 | AC | 52 ms
36,916 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 54 ms
36,980 KB |
testcase_14 | WA | - |
testcase_15 | AC | 57 ms
37,064 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 55 ms
37,032 KB |
testcase_21 | WA | - |
testcase_22 | AC | 52 ms
37,020 KB |
testcase_23 | AC | 52 ms
37,024 KB |
testcase_24 | AC | 54 ms
36,492 KB |
testcase_25 | AC | 53 ms
36,936 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 53 ms
37,016 KB |
testcase_31 | AC | 53 ms
36,816 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 53 ms
37,092 KB |
testcase_37 | AC | 54 ms
36,964 KB |
testcase_38 | WA | - |
testcase_39 | AC | 51 ms
37,156 KB |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 55 ms
36,624 KB |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | AC | 54 ms
36,948 KB |
testcase_47 | WA | - |
testcase_48 | AC | 54 ms
36,716 KB |
testcase_49 | AC | 57 ms
37,152 KB |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | AC | 53 ms
36,856 KB |
testcase_54 | AC | 56 ms
37,024 KB |
testcase_55 | WA | - |
testcase_56 | WA | - |
testcase_57 | AC | 55 ms
37,156 KB |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | WA | - |
testcase_64 | AC | 58 ms
36,628 KB |
testcase_65 | WA | - |
testcase_66 | AC | 55 ms
36,708 KB |
testcase_67 | WA | - |
testcase_68 | WA | - |
testcase_69 | WA | - |
testcase_70 | WA | - |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] values = new int[n]; for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); } if (n == 1) { System.out.println(values[0]); System.out.println(1); return; } else if (n == 2) { if (values[0] < values[1]) { System.out.println(values[1]); System.out.println(2); } else { System.out.println(values[0]); System.out.println(1); } return; } int[] dp = new int[n]; int[] prev = new int[n]; dp[0] = values[0]; prev[0] = -1; dp[1] = values[1]; prev[1] = -1; dp[2] = values[0] + values[1]; prev[2] = 0; for (int i = 3; i < n; i++) { if (dp[i - 2] < dp[i - 3]) { dp[i] = dp[i - 3] + values[i]; prev[i] = i - 3; } else { dp[i] = dp[i - 2] + values[i]; prev[i] = i - 2; } } int idx; int ans; if (dp[n - 1] < dp[n - 2]) { idx = n - 2; ans = dp[n - 2]; } else { idx = n - 1; ans = dp[n - 1]; } ArrayDeque<Integer> deq = new ArrayDeque<>(); while (idx >= 0) { deq.push(idx + 1); idx = prev[idx]; } StringBuilder sb = new StringBuilder(); boolean isFirst = true; while (deq.size() > 0) { if (!isFirst) { sb.append(" "); } isFirst = false; sb.append(deq.poll()); } System.out.println(ans); System.out.println(sb); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }