結果
問題 | No.2178 Payable Magic Items |
ユーザー | tenten |
提出日時 | 2023-03-30 10:10:54 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 781 ms / 4,000 ms |
コード長 | 2,802 bytes |
コンパイル時間 | 2,916 ms |
コンパイル使用メモリ | 85,684 KB |
実行使用メモリ | 165,228 KB |
最終ジャッジ日時 | 2024-09-21 21:34:42 |
合計ジャッジ時間 | 16,237 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 58 ms
50,264 KB |
testcase_01 | AC | 60 ms
50,340 KB |
testcase_02 | AC | 56 ms
50,380 KB |
testcase_03 | AC | 557 ms
158,236 KB |
testcase_04 | AC | 55 ms
50,184 KB |
testcase_05 | AC | 588 ms
158,488 KB |
testcase_06 | AC | 560 ms
158,512 KB |
testcase_07 | AC | 55 ms
50,188 KB |
testcase_08 | AC | 573 ms
158,504 KB |
testcase_09 | AC | 181 ms
67,368 KB |
testcase_10 | AC | 59 ms
50,184 KB |
testcase_11 | AC | 756 ms
161,316 KB |
testcase_12 | AC | 781 ms
165,192 KB |
testcase_13 | AC | 754 ms
161,188 KB |
testcase_14 | AC | 760 ms
165,228 KB |
testcase_15 | AC | 767 ms
161,084 KB |
testcase_16 | AC | 780 ms
165,076 KB |
testcase_17 | AC | 769 ms
160,956 KB |
testcase_18 | AC | 97 ms
51,540 KB |
testcase_19 | AC | 311 ms
75,792 KB |
testcase_20 | AC | 60 ms
49,804 KB |
testcase_21 | AC | 103 ms
51,308 KB |
testcase_22 | AC | 120 ms
52,004 KB |
testcase_23 | AC | 62 ms
50,308 KB |
testcase_24 | AC | 773 ms
161,120 KB |
testcase_25 | AC | 747 ms
160,700 KB |
testcase_26 | AC | 335 ms
74,452 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(); } }