結果
| 問題 |
No.171 スワップ文字列(Med)
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-01-26 19:29:49 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 56 ms / 1,000 ms |
| コード長 | 2,790 bytes |
| コンパイル時間 | 2,518 ms |
| コンパイル使用メモリ | 91,764 KB |
| 実行使用メモリ | 37,320 KB |
| 最終ジャッジ日時 | 2024-06-27 11:23:25 |
| 合計ジャッジ時間 | 3,999 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.stream.*;
public class Main {
static final int MOD = 573;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int[] counts = new int[26];
int total = 0;
for (char c : sc.next().toCharArray()) {
counts[c - 'A']++;
total++;
}
HashMap<Integer, Integer> all = new HashMap<>();
for (int i = 2; i <= total; i++) {
int x = i;
for (int j = 2; j <= Math.sqrt(x); j++) {
while (x % j == 0) {
all.put(j, all.getOrDefault(j, 0) + 1);
x /= j;
}
}
if (x > 1) {
all.put(x, all.getOrDefault(x, 0) + 1);
}
}
for (int num : counts) {
for (int i = 2; i <= num; i++) {
int x = i;
for (int j = 2; j <= Math.sqrt(x); j++) {
while (x % j == 0) {
all.put(j, all.get(j) - 1);
x /= j;
}
}
if (x > 1) {
all.put(x, all.get(x) - 1);
}
}
}
int ans = 1;
for (int x : all.keySet()) {
int v = all.get(x);
for (int i = 0; i < v; i++) {
ans *= x;
ans %= MOD;
}
}
ans += MOD - 1;
ans %= MOD;
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();
}
}
tenten