結果

問題 No.1617 Palindrome Removal
ユーザー merlinmerlin
提出日時 2021-07-22 21:56:41
言語 Java19
(openjdk 21)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 909 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 73,800 KB
実行使用メモリ 55,108 KB
最終ジャッジ日時 2023-09-24 16:46:39
合計ジャッジ時間 5,683 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
54,460 KB
testcase_01 AC 141 ms
54,332 KB
testcase_02 AC 144 ms
54,804 KB
testcase_03 AC 147 ms
54,764 KB
testcase_04 AC 149 ms
54,876 KB
testcase_05 AC 138 ms
54,932 KB
testcase_06 AC 150 ms
54,696 KB
testcase_07 AC 124 ms
54,276 KB
testcase_08 AC 43 ms
49,108 KB
testcase_09 AC 43 ms
49,008 KB
testcase_10 AC 146 ms
54,684 KB
testcase_11 AC 144 ms
55,108 KB
testcase_12 AC 148 ms
54,636 KB
testcase_13 AC 153 ms
54,460 KB
testcase_14 AC 45 ms
49,408 KB
testcase_15 AC 45 ms
47,188 KB
testcase_16 AC 47 ms
49,072 KB
testcase_17 AC 42 ms
49,152 KB
testcase_18 AC 43 ms
49,280 KB
testcase_19 AC 43 ms
49,532 KB
testcase_20 AC 43 ms
49,096 KB
testcase_21 AC 42 ms
49,232 KB
testcase_22 AC 42 ms
49,328 KB
testcase_23 AC 42 ms
49,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
            {
                if(n==3) ans=-1;
                else ans=n-2;
            }
            else ans=n-2;
        }
        System.out.println(ans);
    }
}
0