結果

問題 No.1617 Palindrome Removal
ユーザー merlinmerlin
提出日時 2021-07-22 21:55:51
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 909 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 73,648 KB
実行使用メモリ 55,364 KB
最終ジャッジ日時 2023-09-24 16:45:29
合計ジャッジ時間 5,830 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
54,640 KB
testcase_01 AC 150 ms
54,640 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 150 ms
54,632 KB
testcase_05 AC 139 ms
54,688 KB
testcase_06 AC 148 ms
54,980 KB
testcase_07 AC 121 ms
54,372 KB
testcase_08 AC 43 ms
48,996 KB
testcase_09 AC 43 ms
49,048 KB
testcase_10 AC 136 ms
54,240 KB
testcase_11 AC 135 ms
54,400 KB
testcase_12 AC 151 ms
54,880 KB
testcase_13 AC 149 ms
54,592 KB
testcase_14 AC 44 ms
49,228 KB
testcase_15 AC 43 ms
49,036 KB
testcase_16 AC 42 ms
49,328 KB
testcase_17 AC 43 ms
49,060 KB
testcase_18 AC 43 ms
49,176 KB
testcase_19 AC 44 ms
49,240 KB
testcase_20 AC 43 ms
49,056 KB
testcase_21 AC 43 ms
49,256 KB
testcase_22 AC 42 ms
49,236 KB
testcase_23 AC 44 ms
49,004 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-1;
            }
            else ans=n-2;
        }
        System.out.println(ans);
    }
}
0