結果
問題 | No.2449 square_permutation |
ユーザー | tenten |
提出日時 | 2023-12-12 14:04:05 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,712 ms / 2,000 ms |
コード長 | 2,417 bytes |
コンパイル時間 | 2,882 ms |
コンパイル使用メモリ | 88,020 KB |
実行使用メモリ | 140,100 KB |
最終ジャッジ日時 | 2023-12-12 14:04:36 |
合計ジャッジ時間 | 30,040 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 64 ms
54,632 KB |
testcase_01 | AC | 65 ms
54,748 KB |
testcase_02 | AC | 68 ms
54,640 KB |
testcase_03 | AC | 69 ms
52,748 KB |
testcase_04 | AC | 71 ms
54,772 KB |
testcase_05 | AC | 88 ms
55,252 KB |
testcase_06 | AC | 668 ms
83,248 KB |
testcase_07 | AC | 735 ms
81,584 KB |
testcase_08 | AC | 772 ms
83,108 KB |
testcase_09 | AC | 787 ms
86,504 KB |
testcase_10 | AC | 1,187 ms
108,748 KB |
testcase_11 | AC | 1,242 ms
108,740 KB |
testcase_12 | AC | 1,194 ms
106,764 KB |
testcase_13 | AC | 1,712 ms
140,100 KB |
testcase_14 | AC | 1,597 ms
139,348 KB |
testcase_15 | AC | 1,658 ms
140,036 KB |
testcase_16 | AC | 1,605 ms
139,628 KB |
testcase_17 | AC | 1,612 ms
139,280 KB |
testcase_18 | AC | 1,472 ms
117,464 KB |
testcase_19 | AC | 1,617 ms
139,672 KB |
testcase_20 | AC | 1,675 ms
140,032 KB |
testcase_21 | AC | 1,658 ms
140,028 KB |
testcase_22 | AC | 66 ms
54,652 KB |
testcase_23 | AC | 1,691 ms
140,080 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(); ArrayList<Integer> squares = new ArrayList<>(); for (int i = 2; i * i <= n; i++) { squares.add(i * i); } HashMap<Integer, TreeSet<Integer>> groups = new HashMap<>(); int[] values = new int[n + 1]; for (int i = 1; i <= n; i++) { values[i] = i; for (int x : squares) { if (values[i] < x) { break; } while (values[i] % x == 0) { values[i] /= x; } } if (!groups.containsKey(values[i])) { groups.put(values[i], new TreeSet<>()); } groups.get(values[i]).add(i); } int[] ans = new int[n]; for (int i = 1; i <= n; i++) { ans[i - 1] = groups.get(values[i]).pollLast(); } System.out.println(String.join(" ", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new))); } } 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(); } }