結果

問題 No.588 空白と回文
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-14 00:14:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 3,878 ms
コンパイル使用メモリ 73,964 KB
実行使用メモリ 59,292 KB
最終ジャッジ日時 2023-08-21 04:17:15
合計ジャッジ時間 8,024 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
56,508 KB
testcase_01 AC 120 ms
55,568 KB
testcase_02 AC 121 ms
55,636 KB
testcase_03 AC 200 ms
59,116 KB
testcase_04 AC 119 ms
55,240 KB
testcase_05 AC 117 ms
55,584 KB
testcase_06 AC 121 ms
55,388 KB
testcase_07 AC 118 ms
55,712 KB
testcase_08 AC 119 ms
55,716 KB
testcase_09 AC 119 ms
55,544 KB
testcase_10 AC 120 ms
55,524 KB
testcase_11 AC 201 ms
59,292 KB
testcase_12 AC 203 ms
59,116 KB
testcase_13 AC 124 ms
55,636 KB
testcase_14 AC 121 ms
55,772 KB
testcase_15 AC 119 ms
55,912 KB
testcase_16 AC 119 ms
55,732 KB
testcase_17 AC 191 ms
59,044 KB
testcase_18 AC 120 ms
55,816 KB
testcase_19 AC 119 ms
55,724 KB
testcase_20 AC 200 ms
58,992 KB
testcase_21 AC 195 ms
58,672 KB
testcase_22 AC 201 ms
59,292 KB
testcase_23 AC 192 ms
58,580 KB
testcase_24 AC 119 ms
55,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		String s = sc.next();
		
		//まずは、端以外の文字を中心にして調べる
		int ans1 = 0;
		for (int i=1; i<s.length()-1; i++) {
			StringBuilder sb = new StringBuilder(s);
			StringBuilder L = new StringBuilder(sb.delete(i,sb.length()));
			sb = new StringBuilder(s);
			StringBuilder R = new StringBuilder(sb.delete(0,i+1));
			L.reverse();
			
			int max1 = 0;
			for (int j=0; j<Math.min(L.length(),R.length()); j++) {
				if (L.charAt(j)==R.charAt(j)) {max1++;}
			}
			ans1 = Math.max(ans1,max1);
		}
		ans1 = ans1*2+1;
		
		
		//次、基準が文字の真ん中の場合
		int ans2 = 0;
		for (int i=1; i<s.length(); i++) {
			StringBuilder sb = new StringBuilder(s);
			StringBuilder L = new StringBuilder(sb.delete(i,sb.length()));
			sb = new StringBuilder(s);
			StringBuilder R = new StringBuilder(sb.delete(0,i));
			L.reverse();
			
			int max2 = 0;
			for (int j=0; j<Math.min(L.length(),R.length()); j++) {
				if (L.charAt(j)==R.charAt(j)) {max2++;}
			}
			ans2 = Math.max(ans2,max2);
		}
		ans2 = ans2*2;
		
		System.out.println(Math.max(ans1,ans2));
	}
}
0