結果
| 問題 |
No.170 スワップ文字列(Easy)
|
| コンテスト | |
| ユーザー |
nCk_cv
|
| 提出日時 | 2016-02-19 00:26:34 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,117 ms / 5,000 ms |
| コード長 | 960 bytes |
| コンパイル時間 | 2,368 ms |
| コンパイル使用メモリ | 79,516 KB |
| 実行使用メモリ | 126,924 KB |
| 最終ジャッジ日時 | 2024-12-23 00:36:48 |
| 合計ジャッジ時間 | 10,173 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
import java.util.*;
import java.awt.geom.*;
import java.io.*;
class Main {
static HashMap<String,Boolean> map = new HashMap<String,Boolean>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String in = sc.next();
StringBuilder a = new StringBuilder(in);
dfs(a);
System.out.println(map.size()-1);
}
static void dfs(StringBuilder a) {
ArrayDeque<StringBuilder> queue = new ArrayDeque<StringBuilder>();
queue.add(new StringBuilder(a));
while(!queue.isEmpty()) {
a = queue.pollFirst();
String t = a.toString();
if(map.containsKey(a.toString())) continue;
map.put(a.toString(), true);
int tmp = a.length();
for(int i = 0; i < tmp; i++) {
char b = a.charAt(i);
for(int j = i+1; j < tmp; j++) {
a = a.replace(i, i+1, String.valueOf(a.charAt(j)));
a = a.replace(j, j+1, String.valueOf(b));
queue.add(new StringBuilder(a));
a = new StringBuilder(t);
}
}
}
}
}
nCk_cv