結果

問題 No.588 空白と回文
ユーザー tentententen
提出日時 2022-10-06 18:47:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,754 bytes
コンパイル時間 4,157 ms
コンパイル使用メモリ 74,084 KB
実行使用メモリ 51,980 KB
最終ジャッジ日時 2023-09-01 23:40:14
合計ジャッジ時間 6,874 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,396 KB
testcase_01 AC 43 ms
49,272 KB
testcase_02 AC 44 ms
49,284 KB
testcase_03 AC 58 ms
50,124 KB
testcase_04 AC 44 ms
49,488 KB
testcase_05 AC 44 ms
49,796 KB
testcase_06 AC 44 ms
49,588 KB
testcase_07 AC 44 ms
49,904 KB
testcase_08 AC 44 ms
49,368 KB
testcase_09 AC 44 ms
49,680 KB
testcase_10 AC 44 ms
49,456 KB
testcase_11 AC 59 ms
51,632 KB
testcase_12 AC 54 ms
50,428 KB
testcase_13 AC 44 ms
49,380 KB
testcase_14 AC 42 ms
49,264 KB
testcase_15 AC 42 ms
49,780 KB
testcase_16 AC 43 ms
49,804 KB
testcase_17 AC 54 ms
50,088 KB
testcase_18 AC 44 ms
49,924 KB
testcase_19 AC 43 ms
49,388 KB
testcase_20 AC 60 ms
51,876 KB
testcase_21 AC 71 ms
51,936 KB
testcase_22 AC 62 ms
51,808 KB
testcase_23 AC 69 ms
51,980 KB
testcase_24 AC 43 ms
49,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] values = sc.next().toCharArray();
        int max = 0;
        for (int i = 0; i < values.length; i++) {
            int left = i;
            int right = i;
            int count1 = -1;
            while (left >= 0 && right < values.length) {
                if (values[left] == values[right]) {
                    count1 += 2;
                }
                left--;
                right++;
            }
            max = Math.max(max, count1);
            left = i;
            right = i + 1;
            int count2 = 0;
            while (left >= 0 && right < values.length) {
                if (values[left] == values[right]) {
                    count2 += 2;
                }
                left--;
                right++;
            }
            max = Math.max(max, count2);
        }
        System.out.println(max);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0