結果
問題 | No.1492 01文字列と転倒 |
ユーザー | tenten |
提出日時 | 2021-05-06 13:19:23 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 3,979 ms / 4,000 ms |
コード長 | 2,346 bytes |
コンパイル時間 | 2,821 ms |
コンパイル使用メモリ | 77,040 KB |
実行使用メモリ | 102,656 KB |
最終ジャッジ日時 | 2023-09-06 03:08:28 |
合計ジャッジ時間 | 40,877 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
49,428 KB |
testcase_01 | AC | 52 ms
49,560 KB |
testcase_02 | AC | 3,791 ms
101,876 KB |
testcase_03 | AC | 3,923 ms
94,536 KB |
testcase_04 | AC | 3,727 ms
101,060 KB |
testcase_05 | AC | 2,878 ms
90,588 KB |
testcase_06 | AC | 3,500 ms
95,340 KB |
testcase_07 | AC | 3,676 ms
94,752 KB |
testcase_08 | AC | 3,979 ms
102,656 KB |
testcase_09 | AC | 54 ms
49,432 KB |
testcase_10 | AC | 48 ms
47,648 KB |
testcase_11 | AC | 46 ms
49,868 KB |
testcase_12 | AC | 54 ms
49,320 KB |
testcase_13 | AC | 48 ms
49,356 KB |
testcase_14 | AC | 3,274 ms
95,428 KB |
testcase_15 | AC | 104 ms
52,000 KB |
testcase_16 | AC | 283 ms
60,532 KB |
testcase_17 | AC | 3,378 ms
90,180 KB |
testcase_18 | AC | 304 ms
61,360 KB |
testcase_19 | AC | 68 ms
49,300 KB |
testcase_20 | AC | 214 ms
56,436 KB |
testcase_21 | AC | 2,693 ms
87,352 KB |
testcase_22 | AC | 291 ms
60,864 KB |
testcase_23 | AC | 170 ms
54,648 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static ArrayList<ArrayList<Integer>> lists = new ArrayList<>(); public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); HashMap<Integer, HashMap<Integer, Integer>> current = new HashMap<>(); current.put(0, new HashMap<>()); current.get(0).put(0, 1); for (int i = 2; i <= n * 2; i++) { HashMap<Integer, HashMap<Integer, Integer>> next = new HashMap<>(); for (int x : current.keySet()) { for (int y : current.get(x).keySet()) { if (i - x <= n) { if (!next.containsKey(x)) { next.put(x, new HashMap<>()); } next.get(x).put(y + x, (next.get(x).getOrDefault(y + x, 0) + current.get(x).get(y)) % m); } if (x < i - x - 1) { if (!next.containsKey(x + 1)) { next.put(x + 1, new HashMap<>()); } next.get(x + 1).put(y, (next.get(x + 1).getOrDefault(y, 0) + current.get(x).get(y)) % m); } } } current = next; } int[] ans = new int[n * n + 1]; for (HashMap<Integer, Integer> map : current.values()) { for (int x : map.keySet()) { ans[x] += map.get(x); ans[x] %= m; } } StringBuilder sb = new StringBuilder(); for (int x : ans) { sb.append(x).append("\n"); } System.out.print(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 String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }