結果

問題 No.273 回文分解
ユーザー htensaihtensai
提出日時 2019-12-30 10:45:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 2,733 ms
コンパイル使用メモリ 78,856 KB
実行使用メモリ 41,404 KB
最終ジャッジ日時 2024-04-25 10:48:06
合計ジャッジ時間 8,660 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
40,888 KB
testcase_01 AC 128 ms
40,924 KB
testcase_02 AC 130 ms
41,100 KB
testcase_03 AC 130 ms
40,812 KB
testcase_04 AC 130 ms
41,032 KB
testcase_05 AC 131 ms
41,344 KB
testcase_06 AC 128 ms
41,184 KB
testcase_07 AC 128 ms
40,976 KB
testcase_08 AC 114 ms
39,744 KB
testcase_09 AC 128 ms
41,316 KB
testcase_10 AC 130 ms
40,880 KB
testcase_11 AC 132 ms
41,088 KB
testcase_12 AC 131 ms
41,216 KB
testcase_13 AC 131 ms
41,404 KB
testcase_14 AC 129 ms
41,168 KB
testcase_15 AC 127 ms
41,340 KB
testcase_16 AC 131 ms
41,080 KB
testcase_17 AC 130 ms
41,232 KB
testcase_18 AC 131 ms
41,140 KB
testcase_19 AC 131 ms
41,088 KB
testcase_20 AC 130 ms
41,120 KB
testcase_21 AC 126 ms
40,996 KB
testcase_22 AC 133 ms
40,864 KB
testcase_23 AC 115 ms
39,692 KB
testcase_24 AC 131 ms
41,020 KB
testcase_25 AC 130 ms
41,096 KB
testcase_26 AC 129 ms
41,328 KB
testcase_27 AC 112 ms
39,952 KB
testcase_28 AC 128 ms
41,328 KB
testcase_29 AC 128 ms
40,940 KB
testcase_30 AC 129 ms
40,920 KB
testcase_31 AC 130 ms
41,312 KB
testcase_32 AC 130 ms
41,216 KB
testcase_33 AC 129 ms
41,312 KB
testcase_34 AC 127 ms
41,012 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 length = arr.length;
        int max = 1;
        for (int i = 0; i < arr.length; i++) {
            int left = i;
            int right = i;
            while (left >= 0 && right < arr.length && arr[left] == arr[right]) {
                if (length != right - left + 1) {
                    max = Math.max(max, right - left + 1);
                }
                left--;
                right++;
            }
            left = i;
            right = i + 1;
            while (left >= 0 && right < arr.length && arr[left] == arr[right]) {
                if (length != right - left + 1) {
                    max = Math.max(max, right - left + 1);
                }
                left--;
                right++;
            }
        }
        System.out.println(max);
    }
}
0