結果

問題 No.171 スワップ文字列(Med)
ユーザー kenkooookenkoooo
提出日時 2015-03-24 23:02:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 181 ms / 1,000 ms
コード長 1,346 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 74,616 KB
実行使用メモリ 56,280 KB
最終ジャッジ日時 2023-09-11 09:59:00
合計ジャッジ時間 4,701 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,848 KB
testcase_01 AC 116 ms
55,888 KB
testcase_02 AC 142 ms
55,820 KB
testcase_03 AC 120 ms
55,480 KB
testcase_04 AC 118 ms
56,136 KB
testcase_05 AC 145 ms
55,888 KB
testcase_06 AC 156 ms
55,964 KB
testcase_07 AC 159 ms
55,632 KB
testcase_08 AC 168 ms
55,768 KB
testcase_09 AC 181 ms
55,972 KB
testcase_10 AC 116 ms
56,280 KB
testcase_11 AC 119 ms
55,860 KB
testcase_12 AC 119 ms
56,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(System.in);
		char[] input = scanner.next().toCharArray();
		scanner.close();

		int[] alphabets = new int[26];
		for (int i = 0; i < input.length; i++) {
			alphabets[(int) input[i] - 'A']++;
		}

		ArrayList<Integer> multiply = new ArrayList<Integer>();
		for (int i = 1; i <= input.length; i++) {
			multiply.add(i);
		}
		int[] m = new int[multiply.size()];
		for (int i = 0; i < multiply.size(); i++) {
			m[i] = multiply.get(i);
		}

		ArrayList<Integer> divders = new ArrayList<Integer>();
		for (int i = 0; i < alphabets.length; i++) {
			for (int j = 1; j <= alphabets[i]; j++) {
				divders.add(j);
			}
		}
		int[] d = new int[divders.size()];
		for (int i = 0; i < divders.size(); i++) {
			d[i] = divders.get(i);
		}

		for (int i = 0; i < d.length; i++) {
			for (int j = 0; j < m.length; j++) {
				long gcd = gcd(d[i], m[j]);
				d[i] /= (int) gcd;
				m[j] /= (int) gcd;
			}
		}

		long ans = 1;
		for (int i = 0; i < m.length; i++) {
			// System.out.println(mIntegers[i]);
			ans *= m[i];
			ans %= 573;
		}

		if (ans == 0) {
			ans += 573;
		}

		System.out.println(ans - 1);

	}

	static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}
0