結果

問題 No.170 スワップ文字列(Easy)
ユーザー fjafjafjafjafjafja
提出日時 2017-10-01 23:45:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 5,000 ms
コード長 630 bytes
コンパイル時間 3,817 ms
コンパイル使用メモリ 78,932 KB
実行使用メモリ 57,536 KB
最終ジャッジ日時 2023-08-09 23:27:10
合計ジャッジ時間 8,142 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
55,484 KB
testcase_01 AC 114 ms
55,436 KB
testcase_02 AC 117 ms
57,536 KB
testcase_03 AC 121 ms
55,616 KB
testcase_04 AC 120 ms
55,640 KB
testcase_05 AC 118 ms
55,340 KB
testcase_06 AC 114 ms
55,564 KB
testcase_07 AC 117 ms
55,740 KB
testcase_08 AC 117 ms
55,372 KB
testcase_09 AC 118 ms
55,828 KB
testcase_10 AC 117 ms
55,636 KB
testcase_11 AC 118 ms
55,396 KB
testcase_12 AC 116 ms
55,656 KB
testcase_13 AC 116 ms
55,456 KB
testcase_14 AC 118 ms
55,584 KB
testcase_15 AC 118 ms
55,480 KB
testcase_16 AC 118 ms
55,768 KB
testcase_17 AC 119 ms
55,532 KB
testcase_18 AC 118 ms
55,476 KB
testcase_19 AC 117 ms
55,676 KB
testcase_20 AC 117 ms
55,756 KB
testcase_21 AC 117 ms
56,288 KB
testcase_22 AC 118 ms
55,840 KB
testcase_23 AC 117 ms
55,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class N170 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		int[] cnt=new int[s.length()];
		for(int i=0;i<s.length();i++){
			if(cnt[i]==-1){
				continue;
			}
			String buf=s.substring(i,i+1);
			cnt[i]=1;
			for(int j=i+1;j<s.length();j++){
				if(buf.equals(s.substring(j,j+1))){
					cnt[i]++;
					cnt[j]=-1;
				}
			}
		}
		int ans=1;
		for(int i=s.length();i>0;i--){
			ans*=i;
		}
		for(int i=0;i<s.length();i++){
			if(cnt[i]>=2){
				for(int j=cnt[i];j>0;j--){
					ans/=j;
				}
			}
		}
		System.out.println(ans-1);
	}

}
0