結果

問題 No.273 回文分解
ユーザー yuppe19 😺yuppe19 😺
提出日時 2015-09-06 17:37:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 728 bytes
コンパイル時間 2,175 ms
コンパイル使用メモリ 71,660 KB
実行使用メモリ 56,412 KB
最終ジャッジ日時 2023-09-07 19:43:49
合計ジャッジ時間 7,949 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,532 KB
testcase_01 AC 124 ms
55,780 KB
testcase_02 AC 123 ms
56,400 KB
testcase_03 AC 122 ms
55,852 KB
testcase_04 AC 123 ms
55,852 KB
testcase_05 AC 123 ms
55,748 KB
testcase_06 AC 122 ms
55,892 KB
testcase_07 AC 123 ms
55,736 KB
testcase_08 AC 121 ms
56,024 KB
testcase_09 AC 123 ms
55,816 KB
testcase_10 AC 127 ms
55,540 KB
testcase_11 AC 124 ms
56,140 KB
testcase_12 AC 123 ms
55,760 KB
testcase_13 AC 122 ms
55,812 KB
testcase_14 AC 126 ms
55,836 KB
testcase_15 AC 121 ms
56,056 KB
testcase_16 AC 121 ms
55,768 KB
testcase_17 AC 122 ms
55,872 KB
testcase_18 AC 124 ms
56,412 KB
testcase_19 AC 122 ms
56,056 KB
testcase_20 AC 123 ms
55,692 KB
testcase_21 AC 122 ms
55,784 KB
testcase_22 AC 125 ms
55,980 KB
testcase_23 AC 132 ms
55,936 KB
testcase_24 AC 125 ms
53,656 KB
testcase_25 AC 124 ms
55,740 KB
testcase_26 AC 125 ms
56,176 KB
testcase_27 AC 131 ms
56,052 KB
testcase_28 AC 128 ms
55,760 KB
testcase_29 AC 127 ms
55,772 KB
testcase_30 AC 126 ms
55,912 KB
testcase_31 AC 126 ms
56,000 KB
testcase_32 AC 124 ms
55,856 KB
testcase_33 AC 124 ms
56,076 KB
testcase_34 AC 126 ms
56,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import static java.lang.Math.*;

public class Main {
  boolean isPalindrome(String s) {
    int n = s.length();
    for(int i=0; i<n/2; i++) {
      if(s.charAt(i) != s.charAt(n-i-1)) { return false; }
    }
    return true;
  }
  private void solve() {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    int n = s.length();
    int res = 0;
    for(int i=0; i<n; i++) {
      for(int j=i; j<n; j++) {
        if(i==0 && j==n-1) { continue; }
        String t = s.substring(i, j+1);
        if(isPalindrome(t)) {
          res = max(res, j-i+1);
        }
      }
    }
    System.out.printf("%d\n", res);
  }

  public static void main(String[] args) {
    new Main().solve();
  }
}
0