結果
問題 | No.1606 Stuffed Animals Keeper |
ユーザー | tenten |
提出日時 | 2021-11-29 15:56:50 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,321 bytes |
コンパイル時間 | 2,951 ms |
コンパイル使用メモリ | 75,988 KB |
実行使用メモリ | 157,356 KB |
最終ジャッジ日時 | 2023-09-15 08:17:56 |
合計ジャッジ時間 | 22,712 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
49,224 KB |
testcase_01 | AC | 42 ms
49,300 KB |
testcase_02 | AC | 42 ms
49,372 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 66 ms
50,380 KB |
testcase_14 | AC | 73 ms
50,436 KB |
testcase_15 | AC | 66 ms
50,452 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 212 ms
61,244 KB |
testcase_27 | AC | 249 ms
63,692 KB |
testcase_28 | AC | 237 ms
63,792 KB |
testcase_29 | AC | 261 ms
64,792 KB |
testcase_30 | AC | 211 ms
61,132 KB |
testcase_31 | AC | 205 ms
61,236 KB |
testcase_32 | AC | 78 ms
51,624 KB |
testcase_33 | AC | 156 ms
57,592 KB |
testcase_34 | AC | 78 ms
50,284 KB |
testcase_35 | AC | 165 ms
57,680 KB |
testcase_36 | WA | - |
testcase_37 | AC | 153 ms
55,116 KB |
testcase_38 | AC | 130 ms
54,904 KB |
testcase_39 | AC | 67 ms
50,548 KB |
testcase_40 | AC | 69 ms
50,488 KB |
testcase_41 | AC | 65 ms
50,484 KB |
testcase_42 | AC | 65 ms
50,476 KB |
testcase_43 | WA | - |
testcase_44 | AC | 661 ms
140,708 KB |
testcase_45 | AC | 640 ms
129,992 KB |
testcase_46 | AC | 640 ms
129,908 KB |
testcase_47 | AC | 639 ms
130,272 KB |
testcase_48 | AC | 43 ms
49,736 KB |
testcase_49 | AC | 41 ms
49,320 KB |
testcase_50 | AC | 42 ms
49,176 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); ArrayList<Integer> meat = new ArrayList<>(); ArrayList<Integer> bege = new ArrayList<>(); int total = 0; int count = 0; for (int i = 0; i < n; i++) { int x = sc.nextInt(); if (x == 2 && total > 0 && count > 0 && count < total) { meat.add(count); bege.add(total - count); count = 0; total = 0; } if (x == 0 || x == 1) { total++; } if (x == 1) { count++; } } if (total > 0 && count > 0 && count < total) { meat.add(count); bege.add(total - count); } int length = meat.size(); ArrayList<HashMap<Integer, Integer>> dp = new ArrayList<>(); for (int i = 0; i <= length; i++) { dp.add(new HashMap<>()); } dp.get(0).put(0, 0); for (int i = 1; i <= length; i++) { int m = meat.get(i - 1); int b = bege.get(i - 1); for (int x : dp.get(i - 1).keySet()) { dp.get(i).put(x + m, Math.min(dp.get(i).getOrDefault(x + m, Integer.MAX_VALUE), dp.get(i - 1).get(x) + m)); dp.get(i).put(x - b, Math.min(dp.get(i).getOrDefault(x - b, Integer.MAX_VALUE), dp.get(i - 1).get(x))); } } System.out.println(dp.get(length).getOrDefault(0, -1)); } } 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 next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }