結果

問題 No.170 スワップ文字列(Easy)
ユーザー rf141rf141
提出日時 2015-12-19 22:14:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 120 ms / 5,000 ms
コード長 1,152 bytes
コンパイル時間 2,686 ms
コンパイル使用メモリ 76,600 KB
実行使用メモリ 56,004 KB
最終ジャッジ日時 2023-08-24 16:24:28
合計ジャッジ時間 6,338 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
55,552 KB
testcase_01 AC 116 ms
55,760 KB
testcase_02 AC 115 ms
55,816 KB
testcase_03 AC 116 ms
55,548 KB
testcase_04 AC 118 ms
53,704 KB
testcase_05 AC 118 ms
55,796 KB
testcase_06 AC 118 ms
55,812 KB
testcase_07 AC 118 ms
55,688 KB
testcase_08 AC 118 ms
55,688 KB
testcase_09 AC 119 ms
55,884 KB
testcase_10 AC 119 ms
55,948 KB
testcase_11 AC 118 ms
55,908 KB
testcase_12 AC 117 ms
55,800 KB
testcase_13 AC 116 ms
55,540 KB
testcase_14 AC 116 ms
55,688 KB
testcase_15 AC 117 ms
55,956 KB
testcase_16 AC 116 ms
55,728 KB
testcase_17 AC 117 ms
55,676 KB
testcase_18 AC 116 ms
56,004 KB
testcase_19 AC 118 ms
55,784 KB
testcase_20 AC 117 ms
55,712 KB
testcase_21 AC 120 ms
55,832 KB
testcase_22 AC 116 ms
55,728 KB
testcase_23 AC 117 ms
55,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main{
	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		System.out.println(calc(s));
	}

	public static int calc(String str){
		
		LinkedList<Integer> overlap = new LinkedList<Integer>();
		String[] sp = str.split("");
		Arrays.sort(sp,new Comparator<String>(){
			@Override
			public int compare(String obj0,String obj1){
				return obj0.compareTo(obj1);
			}
		});

		int count = 1;
		String now = "";
		for(int i = 0; i < str.length(); i++){
			now = sp[i];
			if(now.equals("n"))continue;
			sp[i] = "n";
			for(int j = i; j < str.length(); j++){
				if(sp[j].equals("n"))continue;
				if(now.equals(sp[j])){
					count++;
					sp[j] = "n";
				}
			}
			overlap.add(count);
			count = 1;
		}

		int result = 1;
		for(int i = str.length(); 1 <= i; i--){
			result *= i;
		}

		int subresult = 1;
		int r = 1;
		int next = 0;
		for(Iterator<Integer> it = overlap.iterator(); it.hasNext();){
			next = it.next();
			if(next == 1)continue;
			for(int i = next; 1 <= i; i--){
				r*=i;
			}
			subresult*=r;
			r = 1;
		}
		return (result/subresult)-1;

	}
}
0