結果
問題 | No.588 空白と回文 |
ユーザー | 夕叢霧香(ゆうむらきりか) |
提出日時 | 2017-11-03 22:34:33 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 133 ms / 2,000 ms |
コード長 | 883 bytes |
コンパイル時間 | 2,147 ms |
コンパイル使用メモリ | 74,716 KB |
実行使用メモリ | 42,084 KB |
最終ジャッジ日時 | 2024-05-02 05:06:55 |
合計ジャッジ時間 | 5,753 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 99 ms
40,016 KB |
testcase_01 | AC | 100 ms
40,332 KB |
testcase_02 | AC | 108 ms
41,220 KB |
testcase_03 | AC | 113 ms
41,316 KB |
testcase_04 | AC | 93 ms
39,728 KB |
testcase_05 | AC | 103 ms
40,420 KB |
testcase_06 | AC | 106 ms
41,040 KB |
testcase_07 | AC | 96 ms
40,064 KB |
testcase_08 | AC | 111 ms
40,812 KB |
testcase_09 | AC | 95 ms
40,120 KB |
testcase_10 | AC | 93 ms
40,184 KB |
testcase_11 | AC | 119 ms
41,196 KB |
testcase_12 | AC | 112 ms
41,040 KB |
testcase_13 | AC | 102 ms
40,332 KB |
testcase_14 | AC | 113 ms
41,080 KB |
testcase_15 | AC | 112 ms
40,976 KB |
testcase_16 | AC | 98 ms
40,016 KB |
testcase_17 | AC | 130 ms
41,808 KB |
testcase_18 | AC | 117 ms
41,172 KB |
testcase_19 | AC | 112 ms
40,884 KB |
testcase_20 | AC | 125 ms
41,976 KB |
testcase_21 | AC | 133 ms
42,028 KB |
testcase_22 | AC | 128 ms
42,084 KB |
testcase_23 | AC | 112 ms
40,848 KB |
testcase_24 | AC | 109 ms
40,640 KB |
ソースコード
import java.util.*; class Main { static int longestPalindrome(String s) { int length = s.length(); int count = 0; for (int i = 0; i < length / 2; ++i) { if (s.charAt(i) == s.charAt(length - 1 - i)) { count += 2; } } if (length % 2 == 1) { count++; } return count; } public static void main(String[] args) { Scanner scan = new Scanner(System.in); String s = scan.next(); int length = s.length(); int maximum = 0; for (int i = 1; i <= length; ++i) { maximum = Math.max(maximum, longestPalindrome(s.substring(0, i))); } for (int i = 1; i <= length; ++i) { maximum = Math.max(maximum, longestPalindrome(s.substring(length - i, length))); } System.out.println(maximum); } }