結果

問題 No.273 回文分解
ユーザー GrenacheGrenache
提出日時 2015-08-28 22:41:08
言語 Java19
(openjdk 21)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 882 bytes
コンパイル時間 3,343 ms
コンパイル使用メモリ 74,180 KB
実行使用メモリ 55,984 KB
最終ジャッジ日時 2023-09-07 19:39:31
合計ジャッジ時間 8,957 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,848 KB
testcase_01 AC 121 ms
55,876 KB
testcase_02 AC 120 ms
55,852 KB
testcase_03 AC 122 ms
55,716 KB
testcase_04 AC 120 ms
55,544 KB
testcase_05 AC 120 ms
55,640 KB
testcase_06 AC 121 ms
55,868 KB
testcase_07 AC 122 ms
55,476 KB
testcase_08 AC 121 ms
55,872 KB
testcase_09 AC 122 ms
55,580 KB
testcase_10 AC 123 ms
55,800 KB
testcase_11 AC 120 ms
55,704 KB
testcase_12 AC 120 ms
55,464 KB
testcase_13 AC 121 ms
55,572 KB
testcase_14 AC 120 ms
55,396 KB
testcase_15 AC 120 ms
55,712 KB
testcase_16 AC 119 ms
55,620 KB
testcase_17 AC 120 ms
55,772 KB
testcase_18 AC 119 ms
55,984 KB
testcase_19 AC 120 ms
55,308 KB
testcase_20 AC 119 ms
55,628 KB
testcase_21 AC 121 ms
55,560 KB
testcase_22 AC 121 ms
55,804 KB
testcase_23 AC 121 ms
55,676 KB
testcase_24 AC 119 ms
55,528 KB
testcase_25 AC 119 ms
53,652 KB
testcase_26 AC 119 ms
55,724 KB
testcase_27 AC 120 ms
55,388 KB
testcase_28 AC 119 ms
55,872 KB
testcase_29 AC 122 ms
55,332 KB
testcase_30 AC 124 ms
55,728 KB
testcase_31 AC 119 ms
55,472 KB
testcase_32 AC 120 ms
55,604 KB
testcase_33 AC 118 ms
55,568 KB
testcase_34 AC 119 ms
55,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder273 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char[] s = sc.next().toCharArray();
        int n = s.length;
        int max = 1;
        for (int i = 0; i < n; i++) {
        	for (int j = i + 1; j < n - 1; j++) {
        		max = Math.max(max, check(s, i, j));
        	}
        }
        for (int i = 1; i < n; i++) {
        	for (int j = i + 1; j < n; j++) {
        		max = Math.max(max, check(s, i, j));
        	}
        }

        System.out.println(max);

        sc.close();
    }

	private static int check(char[] s, int i, int j) {
		int n = (j - i + 1) / 2;
		boolean flag = true;
		for (int k = 0; k < n; k++) {
			if (s[i + k] != s[j - k]) {
				flag = false;
				break;
			}
		}
		
		if (flag) {
			return j - i + 1;
		} else {
			return 0;
		}
	}
}
0