結果
| 問題 |
No.171 スワップ文字列(Med)
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-05-20 11:19:51 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 109 ms / 1,000 ms |
| コード長 | 2,084 bytes |
| コンパイル時間 | 2,295 ms |
| コンパイル使用メモリ | 80,396 KB |
| 実行使用メモリ | 56,260 KB |
| 最終ジャッジ日時 | 2024-10-10 07:12:42 |
| 合計ジャッジ時間 | 4,054 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
static final int MOD = 573;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int count = 0;
int[] alpha = new int[26];
for (char c : sc.next().toCharArray()) {
alpha[c - 'A']++;
count++;
}
ArrayList<HashMap<Integer, Integer>> list = new ArrayList<>();
list.add(new HashMap<>());
list.add(new HashMap<>());
for (int i = 2; i <= count; i++) {
HashMap<Integer, Integer> tmp = (HashMap<Integer, Integer>)list.get(i - 1).clone();
int x = i;
for (int j = 2; j <= Math.sqrt(x); j++) {
while (x % j == 0) {
tmp.put(j, tmp.getOrDefault(j, 0) + 1);
x /= j;
}
}
if (x > 1) {
tmp.put(x, tmp.getOrDefault(x, 0) + 1);
}
list.add(tmp);
}
HashMap<Integer, Integer> base = (HashMap<Integer, Integer>)list.get(count);
for (int x : alpha) {
for (int y : list.get(x).keySet()) {
base.put(y, base.get(y) - list.get(x).get(y));
}
}
int ans = 1;
for (int x : base.keySet()) {
for (int i = 0; i < base.get(x); i++) {
ans *= x;
ans %= MOD;
}
}
System.out.println((ans - 1 + MOD) % MOD);
}
}
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();
}
}
tenten