結果
問題 | No.273 回文分解 |
ユーザー | uafr_cs |
提出日時 | 2015-09-02 21:14:46 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,115 bytes |
コンパイル時間 | 2,740 ms |
コンパイル使用メモリ | 79,004 KB |
実行使用メモリ | 64,584 KB |
最終ジャッジ日時 | 2023-08-25 00:14:31 |
合計ジャッジ時間 | 11,069 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 120 ms
62,844 KB |
testcase_01 | AC | 119 ms
55,868 KB |
testcase_02 | AC | 120 ms
55,728 KB |
testcase_03 | AC | 118 ms
54,284 KB |
testcase_04 | AC | 117 ms
55,716 KB |
testcase_05 | AC | 131 ms
55,872 KB |
testcase_06 | AC | 119 ms
55,540 KB |
testcase_07 | AC | 119 ms
55,860 KB |
testcase_08 | AC | 122 ms
55,760 KB |
testcase_09 | AC | 116 ms
55,864 KB |
testcase_10 | AC | 118 ms
55,608 KB |
testcase_11 | AC | 118 ms
55,680 KB |
testcase_12 | AC | 117 ms
55,724 KB |
testcase_13 | AC | 117 ms
55,344 KB |
testcase_14 | AC | 147 ms
56,748 KB |
testcase_15 | AC | 118 ms
55,348 KB |
testcase_16 | AC | 118 ms
55,696 KB |
testcase_17 | AC | 118 ms
55,924 KB |
testcase_18 | AC | 117 ms
55,588 KB |
testcase_19 | AC | 119 ms
55,944 KB |
testcase_20 | AC | 120 ms
55,440 KB |
testcase_21 | AC | 121 ms
55,780 KB |
testcase_22 | AC | 117 ms
55,656 KB |
testcase_23 | AC | 117 ms
55,860 KB |
testcase_24 | AC | 119 ms
55,424 KB |
testcase_25 | AC | 116 ms
55,700 KB |
testcase_26 | TLE | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
ソースコード
import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static boolean is_n_palindrome(String str, final int n){ if(str.length() < n){ return false; } for(int start = 0, end = n - 1; start < end; start++, end--){ if(str.charAt(start) != str.charAt(end)){ return false; } } return true; } public static int dfs(String str, boolean first){ if(!first && is_n_palindrome(str, str.length())){ return str.length(); } int ret = 0; for(int n = str.length() - 1; n >= 1; n--){ if(is_n_palindrome(str, n)){ final int rest = str.length() - n; if(rest <= ret){ continue; } final int dfs = dfs(str.substring(n), false); if(dfs == 0){ continue; } ret = Math.max(ret, Math.max(n, dfs)); } } return Math.max(ret, !first && is_n_palindrome(str, str.length()) ? str.length() : 0); } public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.println(dfs(sc.next(), true)); } }