結果
問題 |
No.170 スワップ文字列(Easy)
|
ユーザー |
|
提出日時 | 2015-12-19 22:14:42 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 140 ms / 5,000 ms |
コード長 | 1,152 bytes |
コンパイル時間 | 2,522 ms |
コンパイル使用メモリ | 79,332 KB |
実行使用メモリ | 43,220 KB |
最終ジャッジ日時 | 2024-12-23 00:33:31 |
合計ジャッジ時間 | 6,723 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
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; } }