結果
問題 | No.170 スワップ文字列(Easy) |
ユーザー | shora_kujira16 |
提出日時 | 2015-03-22 23:32:25 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 245 ms / 5,000 ms |
コード長 | 1,673 bytes |
コンパイル時間 | 2,101 ms |
コンパイル使用メモリ | 75,788 KB |
実行使用メモリ | 58,964 KB |
最終ジャッジ日時 | 2023-08-24 16:05:14 |
合計ジャッジ時間 | 4,930 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
49,496 KB |
testcase_01 | AC | 245 ms
58,588 KB |
testcase_02 | AC | 44 ms
49,496 KB |
testcase_03 | AC | 44 ms
49,580 KB |
testcase_04 | AC | 70 ms
50,312 KB |
testcase_05 | AC | 221 ms
58,920 KB |
testcase_06 | AC | 245 ms
58,964 KB |
testcase_07 | AC | 43 ms
49,456 KB |
testcase_08 | AC | 45 ms
49,420 KB |
testcase_09 | AC | 45 ms
49,376 KB |
testcase_10 | AC | 157 ms
57,432 KB |
testcase_11 | AC | 42 ms
49,644 KB |
testcase_12 | AC | 43 ms
49,440 KB |
testcase_13 | AC | 43 ms
49,496 KB |
testcase_14 | AC | 42 ms
49,336 KB |
testcase_15 | AC | 49 ms
49,448 KB |
testcase_16 | AC | 42 ms
49,364 KB |
testcase_17 | AC | 42 ms
49,392 KB |
testcase_18 | AC | 43 ms
49,380 KB |
testcase_19 | AC | 43 ms
49,740 KB |
testcase_20 | AC | 43 ms
49,844 KB |
testcase_21 | AC | 43 ms
47,412 KB |
testcase_22 | AC | 43 ms
49,420 KB |
testcase_23 | AC | 42 ms
49,536 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { private void run() { String S = read(); HashSet<String> set = new HashSet<String>(); set.add(S); Stack<String> stk = new Stack<String>(); stk.push(S); while (!stk.isEmpty()) { String t = stk.pop(); for (int i = 0; i < t.length() - 1; i++) { char[] uu = t.toCharArray(); char tmp = uu[i]; uu[i] = uu[i + 1]; uu[i + 1] = tmp; String u = new String(uu); if (!set.contains(u)) { set.add(u); stk.push(u); } } } sysout.println(set.size() - 1); } public static void main(String[] args) { new Main().run(); } // flush automatically iff you call `println` or `printf` or `format`. PrintWriter sysout = new PrintWriter(System.out, true); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer buffer = null; String readLine() { buffer = null; try { return in.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } String read() { if (buffer == null || !buffer.hasMoreTokens()) { buffer = new StringTokenizer(readLine()); } return buffer.nextToken(); } int readInt() { return Integer.parseInt(read()); } long readLong() { return Long.parseLong(read()); } double readDouble() { return Double.parseDouble(read()); } }