結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー AsahiAsahi
提出日時 2023-02-03 22:25:33
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,093 bytes
コンパイル時間 3,125 ms
コンパイル使用メモリ 75,784 KB
実行使用メモリ 60,392 KB
最終ジャッジ日時 2023-09-15 18:29:44
合計ジャッジ時間 13,408 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,700 KB
testcase_01 AC 117 ms
55,312 KB
testcase_02 AC 116 ms
55,496 KB
testcase_03 AC 243 ms
58,364 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 303 ms
60,116 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 303 ms
57,984 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 115 ms
55,580 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;

public class Main{
    /* 入出力 */
    static BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static PrintWriter output = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    /* 定数 */
    static final int [] y4 = {0,1,0,-1};
    static final int [] x4 = {1,0,-1,0};
    static final int  INF1 = Integer.MAX_VALUE;
    static final long INF2 = Long.MAX_VALUE;
    static final long MOD1 = (long)1e9+7;
    static final long MOD2 = 998244353;
    /* Main */
    public static void main(String[] args) throws IOException{
        /*
         * 決め打ち二分探索
         */
        String S = sc.next();
        StringBuilder r = new StringBuilder();
        r.append(S);
        String revers = r.reverse().toString();
        int min = S.length();
        int left = 1;
        int right = min;
        int ans = INF1;
        while(left <= right) {
            int x = (left + right)/2;
            if(check(S,x)) right = x-1;
            else left = x+1;
        }
        if(right == S.length()) {
            if(S.equals(revers)) {
                output.print(right);
            }
            else{
                output.print(1);
            }
        }
        else{
            output.print(right);
        }
        output.flush();        
    }
    static boolean check(String s,int mid) {
        boolean flag = false;
        int len = 0;
        int min = INF1;
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<s.length();i++) {
            sb.append(s.substring(i,i+1));
            if(sb.length() >= 2) {
                String bas = sb.toString();
                String rev = sb.reverse().toString();
                if(bas.equals(rev)) {
                    len += bas.length();
                    min = Math.min(bas.length(),min);
                    sb.delete(0,sb.length());
                }
            }
        }
        return min < mid;
    } 
}
0