結果
問題 | No.2178 Payable Magic Items |
ユーザー | tenten |
提出日時 | 2023-01-25 11:00:41 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 331 ms / 4,000 ms |
コード長 | 2,393 bytes |
コンパイル時間 | 6,059 ms |
コンパイル使用メモリ | 87,628 KB |
実行使用メモリ | 61,460 KB |
最終ジャッジ日時 | 2023-09-08 23:00:03 |
合計ジャッジ時間 | 12,897 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
49,324 KB |
testcase_01 | AC | 40 ms
49,424 KB |
testcase_02 | AC | 41 ms
49,460 KB |
testcase_03 | AC | 73 ms
54,796 KB |
testcase_04 | AC | 41 ms
49,424 KB |
testcase_05 | AC | 97 ms
54,036 KB |
testcase_06 | AC | 84 ms
53,220 KB |
testcase_07 | AC | 40 ms
49,468 KB |
testcase_08 | AC | 112 ms
54,592 KB |
testcase_09 | AC | 75 ms
51,908 KB |
testcase_10 | AC | 40 ms
49,548 KB |
testcase_11 | AC | 331 ms
61,460 KB |
testcase_12 | AC | 266 ms
59,872 KB |
testcase_13 | AC | 316 ms
61,228 KB |
testcase_14 | AC | 269 ms
59,524 KB |
testcase_15 | AC | 294 ms
59,540 KB |
testcase_16 | AC | 274 ms
59,792 KB |
testcase_17 | AC | 191 ms
59,552 KB |
testcase_18 | AC | 75 ms
50,936 KB |
testcase_19 | AC | 148 ms
55,976 KB |
testcase_20 | AC | 46 ms
49,388 KB |
testcase_21 | AC | 58 ms
51,104 KB |
testcase_22 | AC | 78 ms
51,636 KB |
testcase_23 | AC | 47 ms
50,260 KB |
testcase_24 | AC | 275 ms
60,840 KB |
testcase_25 | AC | 150 ms
55,716 KB |
testcase_26 | AC | 162 ms
56,600 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int k = sc.nextInt(); int[] base = new int[k]; base[0] = 1; for (int i = 1; i < k; i++) { base[i] = base[i - 1] * 5; } int count = base[k - 1] * 5; boolean[] enables = new boolean[count]; int[] counts = new int[count]; for (int i = 0; i < n; i++) { int mask = 0; for (char c : sc.next().toCharArray()) { mask *= 5; mask += c - '0'; } counts[mask]++; } int ans = 0; for (int i = count - 1; i >= 0; i--) { for (int j = 0; j < k && !enables[i]; j++) { if (i / base[j] % 5 < 4) { enables[i] = enables[i + base[j]]; } } if (enables[i]) { ans += counts[i]; } enables[i] |= (counts[i] > 0); } System.out.println(ans); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); 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 int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }