結果

問題 No.171 スワップ文字列(Med)
ユーザー tentententen
提出日時 2021-05-20 11:19:51
言語 Java19
(openjdk 21)
結果
AC  
実行時間 106 ms / 1,000 ms
コード長 2,084 bytes
コンパイル時間 2,674 ms
コンパイル使用メモリ 76,272 KB
実行使用メモリ 56,752 KB
最終ジャッジ日時 2023-07-31 13:51:13
合計ジャッジ時間 3,827 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,520 KB
testcase_01 AC 43 ms
49,508 KB
testcase_02 AC 81 ms
51,688 KB
testcase_03 AC 46 ms
50,308 KB
testcase_04 AC 48 ms
50,112 KB
testcase_05 AC 76 ms
51,660 KB
testcase_06 AC 89 ms
54,440 KB
testcase_07 AC 98 ms
54,344 KB
testcase_08 AC 106 ms
56,616 KB
testcase_09 AC 103 ms
56,752 KB
testcase_10 AC 43 ms
49,400 KB
testcase_11 AC 43 ms
49,352 KB
testcase_12 AC 44 ms
49,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0