結果
問題 | No.170 スワップ文字列(Easy) |
ユーザー | kuramu |
提出日時 | 2016-01-28 23:06:01 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 46 ms / 5,000 ms |
コード長 | 1,338 bytes |
コンパイル時間 | 2,551 ms |
コンパイル使用メモリ | 75,040 KB |
実行使用メモリ | 49,552 KB |
最終ジャッジ日時 | 2023-08-24 16:26:09 |
合計ジャッジ時間 | 4,584 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
49,208 KB |
testcase_01 | AC | 43 ms
49,284 KB |
testcase_02 | AC | 44 ms
49,092 KB |
testcase_03 | AC | 45 ms
49,356 KB |
testcase_04 | AC | 45 ms
49,376 KB |
testcase_05 | AC | 45 ms
49,140 KB |
testcase_06 | AC | 44 ms
49,124 KB |
testcase_07 | AC | 44 ms
49,184 KB |
testcase_08 | AC | 45 ms
49,196 KB |
testcase_09 | AC | 46 ms
49,552 KB |
testcase_10 | AC | 46 ms
49,096 KB |
testcase_11 | AC | 45 ms
49,268 KB |
testcase_12 | AC | 45 ms
47,308 KB |
testcase_13 | AC | 45 ms
47,564 KB |
testcase_14 | AC | 43 ms
49,128 KB |
testcase_15 | AC | 44 ms
49,284 KB |
testcase_16 | AC | 45 ms
49,192 KB |
testcase_17 | AC | 45 ms
49,376 KB |
testcase_18 | AC | 45 ms
49,124 KB |
testcase_19 | AC | 44 ms
49,464 KB |
testcase_20 | AC | 45 ms
49,388 KB |
testcase_21 | AC | 45 ms
49,276 KB |
testcase_22 | AC | 44 ms
47,676 KB |
testcase_23 | AC | 45 ms
49,192 KB |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; public class Main { public static void main(String[] args) { BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in)); try { String line = stdReader.readLine(); HashMap<Character, Integer> hashMap = new HashMap<>(); ArrayList<Character> charList = new ArrayList<>(); for(int i=0;i<line.length();i++){ if(!hashMap.containsKey(line.charAt(i))){ hashMap.put(line.charAt(i), 1); charList.add(line.charAt(i)); }else{ int num = hashMap.get(line.charAt(i)); hashMap.remove(line.charAt(i)); hashMap.put(line.charAt(i), num+1); } } int ans = 1; int n = line.length(); for(int i=0;i<charList.size();i++){ ans *= comb(n, hashMap.get(charList.get(i))); n -= hashMap.get(charList.get(i)); } System.out.println(ans-1); } catch (IOException e) { e.printStackTrace(); } } public static int comb(int n,int r){ int temp1 = 1; int temp2 = 1; int loop = r; for(int i=0;i<loop;i++){ temp1 *= n--; temp2 *= r--; } return temp1/temp2; } }