結果

問題 No.170 スワップ文字列(Easy)
ユーザー kenji_shioyakenji_shioya
提出日時 2016-06-17 18:12:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 118 ms / 5,000 ms
コード長 956 bytes
コンパイル時間 3,273 ms
コンパイル使用メモリ 75,424 KB
実行使用メモリ 56,116 KB
最終ジャッジ日時 2023-08-24 16:32:47
合計ジャッジ時間 7,245 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
55,928 KB
testcase_01 AC 116 ms
56,076 KB
testcase_02 AC 115 ms
56,116 KB
testcase_03 AC 117 ms
55,784 KB
testcase_04 AC 117 ms
55,992 KB
testcase_05 AC 118 ms
55,636 KB
testcase_06 AC 116 ms
55,640 KB
testcase_07 AC 115 ms
55,912 KB
testcase_08 AC 118 ms
56,024 KB
testcase_09 AC 118 ms
55,904 KB
testcase_10 AC 117 ms
55,768 KB
testcase_11 AC 118 ms
56,000 KB
testcase_12 AC 117 ms
56,096 KB
testcase_13 AC 116 ms
55,820 KB
testcase_14 AC 117 ms
55,952 KB
testcase_15 AC 116 ms
55,636 KB
testcase_16 AC 117 ms
56,028 KB
testcase_17 AC 115 ms
55,416 KB
testcase_18 AC 116 ms
55,564 KB
testcase_19 AC 116 ms
55,568 KB
testcase_20 AC 117 ms
55,460 KB
testcase_21 AC 118 ms
55,924 KB
testcase_22 AC 118 ms
55,656 KB
testcase_23 AC 117 ms
55,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Exercise93{
  public static void main (String[] args){

    Scanner sc = new Scanner(System.in);

    String str = sc.next();

    int baseR = getRoutes(str.length());

    ArrayList<Integer> s = new ArrayList<Integer>();
    ArrayList<Character> done = new ArrayList<Character>();

    for(int i = 0; i < str.length(); i++){
      if(done.indexOf(str.charAt(i)) != -1){
        continue;
      }
      int count = 1;
      for (int j = i + 1; j < str.length(); j++){
        if(str.charAt(i) == str.charAt(j)){
          count++;
        }
      }
      if(count > 0){
        s.add(count);
        done.add(str.charAt(i));
      }
    }
    int sameR = 1;
    for(int i = 0; i < s.size(); i++){
      sameR *= getRoutes(s.get(i));
    }
    System.out.println(baseR / sameR - 1);
  }
  private static int getRoutes(int num){
    int r = 1;
    for (int i = 0; i < num; i++){
      r *= num - i;
    }
    return r;
  }
}
0