結果

問題 No.273 回文分解
ユーザー htensaihtensai
提出日時 2019-11-23 15:11:33
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 946 bytes
コンパイル時間 1,990 ms
コンパイル使用メモリ 77,368 KB
実行使用メモリ 54,204 KB
最終ジャッジ日時 2024-04-19 14:42:47
合計ジャッジ時間 6,945 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 108 ms
40,944 KB
testcase_04 AC 106 ms
40,880 KB
testcase_05 AC 96 ms
40,316 KB
testcase_06 AC 105 ms
40,872 KB
testcase_07 AC 96 ms
40,692 KB
testcase_08 AC 111 ms
41,084 KB
testcase_09 AC 98 ms
40,960 KB
testcase_10 AC 109 ms
41,196 KB
testcase_11 AC 101 ms
40,908 KB
testcase_12 AC 106 ms
40,640 KB
testcase_13 AC 101 ms
40,076 KB
testcase_14 AC 97 ms
40,080 KB
testcase_15 AC 108 ms
41,204 KB
testcase_16 AC 111 ms
40,480 KB
testcase_17 AC 112 ms
41,144 KB
testcase_18 AC 104 ms
41,100 KB
testcase_19 AC 96 ms
40,916 KB
testcase_20 AC 100 ms
41,096 KB
testcase_21 AC 95 ms
41,124 KB
testcase_22 AC 106 ms
41,508 KB
testcase_23 AC 103 ms
40,004 KB
testcase_24 AC 105 ms
40,996 KB
testcase_25 AC 112 ms
40,100 KB
testcase_26 AC 120 ms
40,832 KB
testcase_27 AC 100 ms
40,896 KB
testcase_28 AC 97 ms
40,816 KB
testcase_29 AC 118 ms
40,920 KB
testcase_30 AC 111 ms
40,012 KB
testcase_31 AC 105 ms
41,044 KB
testcase_32 AC 113 ms
39,948 KB
testcase_33 AC 115 ms
39,880 KB
testcase_34 AC 99 ms
39,756 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 max1 = 1;
		int max2 = 1;
		for (int  i = 1; i < arr.length - 1; i++) {
		    int count = 0;
		    int idx = 1;
		    while(i - idx >= 0 && i + idx < arr.length && arr[i - idx] == arr[i + idx]) {
		        count++;
		        idx++;
		    }
		    max1 = Math.max(max1, count * 2 + 1);
		    count = 0;
		    idx = 1;
		    while(i - idx + 1 >= 0 && i + idx < arr.length && arr[i - idx + 1] == arr[i + idx]) {
		        count++;
		        idx++;
		    }
		    max2 = Math.max(max2, count * 2);
		}
		if (arr.length % 2 == 0 && max2 == arr.length) {
		    System.out.println(Math.max(max1, max2 - 2));
		} else if (arr.length % 2 == 1 && max1 == arr.length) {
		    System.out.println(Math.max(max1 - 2, max1));
		} else {
		    System.out.println(Math.max(max1, max2));
		}
	}
}
0