結果

問題 No.588 空白と回文
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-11-03 22:34:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 883 bytes
コンパイル時間 2,064 ms
コンパイル使用メモリ 71,040 KB
実行使用メモリ 55,832 KB
最終ジャッジ日時 2023-08-14 16:59:35
合計ジャッジ時間 6,254 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,184 KB
testcase_01 AC 118 ms
55,524 KB
testcase_02 AC 119 ms
55,424 KB
testcase_03 AC 133 ms
55,576 KB
testcase_04 AC 119 ms
55,648 KB
testcase_05 AC 118 ms
55,636 KB
testcase_06 AC 118 ms
55,640 KB
testcase_07 AC 116 ms
55,524 KB
testcase_08 AC 117 ms
55,416 KB
testcase_09 AC 117 ms
55,480 KB
testcase_10 AC 117 ms
55,520 KB
testcase_11 AC 140 ms
55,832 KB
testcase_12 AC 133 ms
55,588 KB
testcase_13 AC 118 ms
55,604 KB
testcase_14 AC 117 ms
55,488 KB
testcase_15 AC 118 ms
55,520 KB
testcase_16 AC 117 ms
55,584 KB
testcase_17 AC 132 ms
55,572 KB
testcase_18 AC 119 ms
55,640 KB
testcase_19 AC 120 ms
55,636 KB
testcase_20 AC 134 ms
55,832 KB
testcase_21 AC 132 ms
55,568 KB
testcase_22 AC 134 ms
55,748 KB
testcase_23 AC 132 ms
55,568 KB
testcase_24 AC 118 ms
55,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main {
    static int longestPalindrome(String s) {
        int length = s.length();
        int count = 0;
        for (int i = 0; i < length / 2; ++i) {
            if (s.charAt(i) == s.charAt(length - 1 - i)) {
                count += 2;
            }
        }
        if (length % 2 == 1) {
            count++;
        }
        return count;
    }
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
        String s = scan.next();
        int length = s.length();
        int maximum = 0;
        for (int i = 1; i <= length; ++i) {
            maximum = Math.max(maximum, longestPalindrome(s.substring(0, i)));
        }
        for (int i = 1; i <= length; ++i) {
            maximum = Math.max(maximum, longestPalindrome(s.substring(length - i, length)));
        }
        System.out.println(maximum);
    }
}
0