結果
問題 | No.1617 Palindrome Removal |
ユーザー |
![]() |
提出日時 | 2021-07-22 21:26:07 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 607 bytes |
コンパイル時間 | 2,338 ms |
コンパイル使用メモリ | 74,152 KB |
実行使用メモリ | 61,384 KB |
最終ジャッジ日時 | 2024-07-17 16:18:12 |
合計ジャッジ時間 | 8,999 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 WA * 2 |
ソースコード
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);}}}