結果

問題 No.1617 Palindrome Removal
ユーザー ks2m
提出日時 2021-07-22 21:27:09
言語 Java
(openjdk 23)
結果
RE  
実行時間 -
コード長 633 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 74,388 KB
実行使用メモリ 49,464 KB
最終ジャッジ日時 2024-07-17 16:20:58
合計ジャッジ時間 8,719 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 RE * 1
other AC * 7 RE * 13
権限があれば一括ダウンロードができます

ソースコード

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