結果
| 問題 |
No.170 スワップ文字列(Easy)
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-07-29 10:09:06 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 109 ms / 5,000 ms |
| コード長 | 1,549 bytes |
| コンパイル時間 | 2,268 ms |
| コンパイル使用メモリ | 78,236 KB |
| 実行使用メモリ | 47,268 KB |
| 最終ジャッジ日時 | 2024-07-19 01:44:28 |
| 合計ジャッジ時間 | 5,271 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
static HashSet<String> strings = new HashSet<>();
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
char[] input = sc.next().toCharArray();
search(0, input, new char[input.length], new boolean[input.length]);
System.out.println(strings.size() - 1);
}
static void search(int idx, char[] input, char[] output, boolean[] used) {
if (idx >= input.length) {
strings.add(new String(output));
return;
}
for (int i = 0; i < input.length; i++) {
if (used[i]) {
continue;
}
used[i] = true;
output[idx] = input[i];
search(idx + 1, input, output, used);
used[i] = false;
}
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten