結果

問題 No.1617 Palindrome Removal
ユーザー ks2mks2m
提出日時 2021-07-22 21:27:09
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 633 bytes
コンパイル時間 2,877 ms
コンパイル使用メモリ 71,916 KB
実行使用メモリ 47,920 KB
最終ジャッジ日時 2023-09-24 15:34:40
合計ジャッジ時間 9,140 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 274 ms
47,244 KB
testcase_01 AC 276 ms
47,448 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 296 ms
47,920 KB
testcase_07 AC 259 ms
47,208 KB
testcase_08 AC 111 ms
39,480 KB
testcase_09 AC 115 ms
39,488 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 111 ms
39,080 KB
testcase_16 AC 111 ms
39,448 KB
testcase_17 AC 110 ms
39,744 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 111 ms
39,112 KB
testcase_23 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		sc.close();

		int n = s.length;
		boolean all = true;
		boolean kai = true;
		for (int i = 0; i < n; i++) {
			if (s[0] != s[i]) {
				all = false;
			}
			if (s[i] != s[n - 1 - i]) {
				kai = false;
			}
		}
		if (!kai) {
			System.out.println(n);
			return;
		}
		if (all) {
			if (n % 2 == 0) {
				System.out.println(0);
			} else {
				System.out.println(-1);
			}
		} else {
			System.out.println(n - 2);
			throw new Exception();
		}
	}
}
0