結果
問題 | No.2178 Payable Magic Items |
ユーザー | tenten |
提出日時 | 2023-03-30 10:10:54 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 776 ms / 4,000 ms |
コード長 | 2,802 bytes |
コンパイル時間 | 4,133 ms |
コンパイル使用メモリ | 95,632 KB |
実行使用メモリ | 167,256 KB |
最終ジャッジ日時 | 2023-10-21 20:09:27 |
合計ジャッジ時間 | 15,926 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge9 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 56 ms
53,552 KB |
testcase_01 | AC | 55 ms
53,556 KB |
testcase_02 | AC | 55 ms
53,544 KB |
testcase_03 | AC | 553 ms
157,792 KB |
testcase_04 | AC | 56 ms
53,556 KB |
testcase_05 | AC | 574 ms
158,136 KB |
testcase_06 | AC | 560 ms
158,904 KB |
testcase_07 | AC | 56 ms
52,432 KB |
testcase_08 | AC | 574 ms
159,156 KB |
testcase_09 | AC | 185 ms
70,596 KB |
testcase_10 | AC | 58 ms
53,564 KB |
testcase_11 | AC | 764 ms
162,324 KB |
testcase_12 | AC | 763 ms
164,284 KB |
testcase_13 | AC | 763 ms
167,128 KB |
testcase_14 | AC | 767 ms
166,924 KB |
testcase_15 | AC | 776 ms
167,232 KB |
testcase_16 | AC | 766 ms
167,256 KB |
testcase_17 | AC | 742 ms
162,848 KB |
testcase_18 | AC | 100 ms
54,416 KB |
testcase_19 | AC | 309 ms
77,424 KB |
testcase_20 | AC | 61 ms
53,568 KB |
testcase_21 | AC | 102 ms
54,416 KB |
testcase_22 | AC | 99 ms
54,704 KB |
testcase_23 | AC | 62 ms
53,588 KB |
testcase_24 | AC | 771 ms
162,920 KB |
testcase_25 | AC | 747 ms
162,548 KB |
testcase_26 | AC | 333 ms
78,956 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[] pows = new int[k + 1]; pows[0] = 1; for (int i = 1; i <= k; i++) { pows[i] = pows[i - 1] * 5; } int size = pows[k]; ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); for (int i = 0; i < size; i++) { graph.add(new ArrayList<>()); } for (int i = 0; i < size; i++) { int x = i; for (int j = 0; j < k; j++) { if (x % 5 < 4) { graph.get(i + pows[j]).add(i); } x /= 5; } } int[] points = new int[size]; int[] idxes = new int[n]; for (int i = 0; i < n; i++) { char[] inputs = sc.next().toCharArray(); for (int j = 0; j < k; j++) { idxes[i] += pows[j] * (inputs[j] - '0'); } points[idxes[i]] = 1; } int ans = 0; for (int i = size - 1; i >= 0; i--) { for (int x : graph.get(i)) { points[x] += points[i]; if (points[x] > 2) { points[x] = 2; } } } for (int i = 0; i < n; i++) { if (points[idxes[i]] > 1) { ans++; } } 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(); } }