結果

問題 No.171 スワップ文字列(Med)
ユーザー shora_kujira16shora_kujira16
提出日時 2015-03-23 00:16:46
言語 Java19
(openjdk 21)
結果
AC  
実行時間 68 ms / 1,000 ms
コード長 2,509 bytes
コンパイル時間 2,086 ms
コンパイル使用メモリ 75,376 KB
実行使用メモリ 52,212 KB
最終ジャッジ日時 2023-09-11 09:40:47
合計ジャッジ時間 3,492 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,440 KB
testcase_01 AC 40 ms
49,376 KB
testcase_02 AC 46 ms
49,500 KB
testcase_03 AC 42 ms
49,536 KB
testcase_04 AC 43 ms
49,468 KB
testcase_05 AC 44 ms
49,568 KB
testcase_06 AC 48 ms
50,476 KB
testcase_07 AC 68 ms
50,352 KB
testcase_08 AC 57 ms
52,212 KB
testcase_09 AC 49 ms
50,596 KB
testcase_10 AC 41 ms
49,404 KB
testcase_11 AC 41 ms
49,512 KB
testcase_12 AC 41 ms
49,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    private void run() {
        String S = read();
        HashMap<Character, Integer> m = new HashMap<Character, Integer>();
        for (int i = 0; i < S.length(); i++) {
            int now;
            char c = S.charAt(i);
            if (m.containsKey(c)) now = m.get(c);
            else now = 0;
            m.put(c, now + 1);
        }
        int[] mul = new int[S.length() + 1];
        for(int i = 2; i <= S.length(); i++) {
            int v = i;
            while(v != 1) {
                for(int j = 2; j <= v; j++) {
                    if (v % j == 0) {
                        mul[j]++;
                        v /= j;
                        break;
                    }
                }
            }
        }
        for (Map.Entry<Character, Integer> entry : m.entrySet()) {
            int v = entry.getValue();
            for(int j = 2; j <= v; ++j) {
                int w = j;
                while(w != 1) {
                    for (int k = 2; k <= w; k++) {
                        if (w % k == 0) {
                            mul[k]--;
                            w /= k;
                            break;
                        }
                    }
                }
            }
        }
        int MOD = 573;
        int ans = 1;
        for (int i = 2; i <= S.length(); i++) {
            for (int j = 0; j < mul[i]; j++) {
                ans *= i;
                ans %= MOD;
            }
        }
        if (ans == 0) sysout.println(572);
        else sysout.println(ans - 1);
    }

    public static void main(String[] args) {
        new Main().run();
    }

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = null;

    String readLine() {
        buffer = null;
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    String read() {
        if (buffer == null || !buffer.hasMoreTokens()) {
            buffer = new StringTokenizer(readLine());
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }
}
0