結果
問題 | No.170 スワップ文字列(Easy) |
ユーザー |
![]() |
提出日時 | 2015-03-30 12:12:05 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 360 ms / 5,000 ms |
コード長 | 762 bytes |
コンパイル時間 | 2,431 ms |
コンパイル使用メモリ | 88,832 KB |
実行使用メモリ | 51,260 KB |
最終ジャッジ日時 | 2024-12-23 00:21:24 |
合計ジャッジ時間 | 8,425 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import java.util.Scanner; import java.util.TreeSet; public class Main { static TreeSet<String> mStrList = new TreeSet<String>(); static String S = null; public static void main(String[] args) { Scanner sc = new Scanner(System.in); S = sc.next(); String str = ""; boolean[] used = new boolean[S.length()]; solve(str, used); System.out.println(mStrList.size()); } static void solve(String str, boolean[] used) { if(str.length() == S.length()) { if(!str.equals(S)) { mStrList.add(str); } return; } for(int i=0; i<used.length; i++) { if(used[i]) { continue; } String nextStr = str + S.charAt(i); boolean[] nextUsed = used.clone(); nextUsed[i] = true; solve(nextStr, nextUsed); } } }