結果

問題 No.588 空白と回文
ユーザー tentententen
提出日時 2020-11-18 10:47:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 962 bytes
コンパイル時間 1,938 ms
コンパイル使用メモリ 71,000 KB
実行使用メモリ 56,704 KB
最終ジャッジ日時 2023-09-30 14:53:26
合計ジャッジ時間 6,626 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,728 KB
testcase_01 AC 120 ms
55,760 KB
testcase_02 AC 119 ms
55,716 KB
testcase_03 AC 158 ms
55,820 KB
testcase_04 AC 120 ms
55,256 KB
testcase_05 AC 120 ms
54,024 KB
testcase_06 AC 120 ms
55,720 KB
testcase_07 AC 120 ms
55,828 KB
testcase_08 AC 120 ms
55,740 KB
testcase_09 AC 120 ms
55,616 KB
testcase_10 AC 119 ms
55,556 KB
testcase_11 AC 145 ms
56,076 KB
testcase_12 AC 159 ms
56,012 KB
testcase_13 AC 120 ms
55,552 KB
testcase_14 AC 120 ms
55,720 KB
testcase_15 AC 120 ms
54,128 KB
testcase_16 AC 120 ms
55,772 KB
testcase_17 AC 148 ms
56,416 KB
testcase_18 AC 120 ms
55,844 KB
testcase_19 AC 119 ms
55,708 KB
testcase_20 AC 145 ms
55,812 KB
testcase_21 AC 147 ms
56,704 KB
testcase_22 AC 143 ms
55,744 KB
testcase_23 AC 146 ms
56,192 KB
testcase_24 AC 119 ms
55,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int max = 0;
        for (int i = 0; i < arr.length; i++) {
            int left = i;
            int right = i;
            int length = -1;
            while (left >= 0 && right < arr.length) {
                if (arr[left] == arr[right]) {
                    length += 2;
                }
                left--;
                right++;
            }
            max = Math.max(max, length);
            left = i;
            right = i + 1;
            length = 0;
            while (left >= 0 && right < arr.length) {
                if (arr[left] == arr[right]) {
                    length += 2;
                }
                left--;
                right++;
            }
            max = Math.max(max, length);
        }
        System.out.println(max);
    }
}
0