結果
問題 | No.52 よくある文字列の問題 |
ユーザー | t8m8⛄️ |
提出日時 | 2015-04-16 22:10:49 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,703 bytes |
コンパイル時間 | 3,348 ms |
コンパイル使用メモリ | 75,928 KB |
実行使用メモリ | 59,372 KB |
最終ジャッジ日時 | 2023-09-17 20:59:04 |
合計ジャッジ時間 | 5,906 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 120 ms
55,676 KB |
testcase_01 | AC | 119 ms
55,824 KB |
testcase_02 | AC | 118 ms
55,636 KB |
testcase_03 | WA | - |
testcase_04 | AC | 330 ms
59,372 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 118 ms
55,900 KB |
testcase_10 | AC | 117 ms
56,144 KB |
ソースコード
//No.52 よくある文字列の問題 import java.util.*; import java.io.*; import static java.util.Arrays.*; import static java.lang.Math.*; public class No52 { static final Scanner in = new Scanner(System.in); static final PrintWriter out = new PrintWriter(System.out,false); static void solve() { String s = in.next(); HashSet<String> map = new HashSet<String>(); char[] cs = s.toCharArray(); sort(cs); int cnt = 0; do { if (dfs(s,String.valueOf(cs),0)) cnt++; }while(nextPermutation(cs)); out.println(cnt); } static boolean dfs(String s, String t, int idx) { char c = s.charAt(idx); int len = t.length(); if (len == 1) return c == t.charAt(0); if (t.charAt(0) == c && dfs(s,t.substring(1),idx+1)) return true; if (t.charAt(len-1) == c && dfs(s,t.substring(0,len-1),idx+1)) return true; return false; } static boolean nextPermutation(char[] a) { int n = a.length, i, j; for (i=n-2; i>=0 && a[i]>=a[i+1]; i--); if (i == -1) return false; for (j=i+1; j<n && a[i]<a[j]; j++); char temp = a[i]; a[i] = a[j-1]; a[j-1] = temp; for (int l=i+1, r=n-1; l<r; l++,r--) { temp = a[l]; a[l] = a[r]; a[r] = temp; } return true; } public static void main(String[] args) { long start = System.currentTimeMillis(); solve(); out.flush(); long end = System.currentTimeMillis(); //trace(end-start + "ms"); in.close(); out.close(); } static void trace(Object... o) { System.out.println(deepToString(o));} }