結果
問題 | No.1617 Palindrome Removal |
ユーザー | merlin |
提出日時 | 2021-07-22 21:46:53 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 826 bytes |
コンパイル時間 | 2,205 ms |
コンパイル使用メモリ | 72,652 KB |
実行使用メモリ | 55,012 KB |
最終ジャッジ日時 | 2023-09-24 16:23:38 |
合計ジャッジ時間 | 6,010 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 146 ms
54,504 KB |
testcase_01 | AC | 157 ms
54,704 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 159 ms
54,640 KB |
testcase_05 | AC | 140 ms
54,212 KB |
testcase_06 | AC | 157 ms
54,612 KB |
testcase_07 | AC | 121 ms
54,092 KB |
testcase_08 | AC | 45 ms
49,204 KB |
testcase_09 | AC | 44 ms
49,092 KB |
testcase_10 | AC | 144 ms
54,792 KB |
testcase_11 | AC | 142 ms
54,608 KB |
testcase_12 | AC | 141 ms
55,012 KB |
testcase_13 | AC | 153 ms
54,776 KB |
testcase_14 | AC | 44 ms
49,196 KB |
testcase_15 | AC | 43 ms
49,260 KB |
testcase_16 | AC | 44 ms
49,172 KB |
testcase_17 | AC | 46 ms
48,996 KB |
testcase_18 | AC | 43 ms
49,156 KB |
testcase_19 | AC | 43 ms
49,184 KB |
testcase_20 | AC | 44 ms
49,436 KB |
testcase_21 | AC | 44 ms
49,176 KB |
testcase_22 | AC | 44 ms
49,140 KB |
testcase_23 | AC | 44 ms
49,096 KB |
ソースコード
import java.io.*; import java.util.*; class Main { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); char s[]=bu.readLine().toCharArray(); int i,c[]=new int[26],n=s.length; boolean p=true; for(i=0;i<n;i++) { c[s[i]-'a']++; p&=s[i]==s[n-i-1]; } int ans,max=0; for(i=0;i<26;i++) if(c[i]!=0) max=Math.max(max,c[i]); if(!p) ans=n; else { if(max==n) { if(n%2==0) ans=0; else ans=-1; } else if(max==n-1) ans=-1; else ans=n-2; } System.out.println(ans); } }