結果
問題 | No.238 Mr. K's Another Gift |
ユーザー | htensai |
提出日時 | 2020-05-12 16:43:09 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 216 ms / 2,000 ms |
コード長 | 1,490 bytes |
コンパイル時間 | 2,185 ms |
コンパイル使用メモリ | 74,064 KB |
実行使用メモリ | 41,124 KB |
最終ジャッジ日時 | 2023-10-11 16:11:29 |
合計ジャッジ時間 | 12,864 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 118 ms
39,320 KB |
testcase_01 | AC | 116 ms
39,776 KB |
testcase_02 | AC | 118 ms
39,560 KB |
testcase_03 | AC | 122 ms
39,332 KB |
testcase_04 | AC | 139 ms
39,408 KB |
testcase_05 | AC | 206 ms
40,824 KB |
testcase_06 | AC | 207 ms
41,064 KB |
testcase_07 | AC | 207 ms
40,240 KB |
testcase_08 | AC | 216 ms
41,016 KB |
testcase_09 | AC | 207 ms
40,536 KB |
testcase_10 | AC | 120 ms
39,392 KB |
testcase_11 | AC | 115 ms
39,004 KB |
testcase_12 | AC | 116 ms
39,260 KB |
testcase_13 | AC | 128 ms
39,148 KB |
testcase_14 | AC | 189 ms
40,196 KB |
testcase_15 | AC | 191 ms
40,424 KB |
testcase_16 | AC | 199 ms
40,684 KB |
testcase_17 | AC | 193 ms
40,836 KB |
testcase_18 | AC | 196 ms
40,452 KB |
testcase_19 | AC | 187 ms
40,064 KB |
testcase_20 | AC | 117 ms
39,280 KB |
testcase_21 | AC | 117 ms
39,324 KB |
testcase_22 | AC | 118 ms
39,492 KB |
testcase_23 | AC | 121 ms
39,620 KB |
testcase_24 | AC | 135 ms
39,452 KB |
testcase_25 | AC | 136 ms
39,196 KB |
testcase_26 | AC | 205 ms
40,468 KB |
testcase_27 | AC | 209 ms
40,812 KB |
testcase_28 | AC | 209 ms
40,884 KB |
testcase_29 | AC | 206 ms
40,744 KB |
testcase_30 | AC | 116 ms
39,224 KB |
testcase_31 | AC | 119 ms
39,680 KB |
testcase_32 | AC | 118 ms
39,628 KB |
testcase_33 | AC | 134 ms
39,644 KB |
testcase_34 | AC | 186 ms
40,044 KB |
testcase_35 | AC | 192 ms
40,132 KB |
testcase_36 | AC | 192 ms
40,608 KB |
testcase_37 | AC | 192 ms
40,520 KB |
testcase_38 | AC | 193 ms
40,668 KB |
testcase_39 | AC | 189 ms
41,124 KB |
testcase_40 | AC | 116 ms
39,180 KB |
testcase_41 | AC | 114 ms
39,528 KB |
testcase_42 | AC | 113 ms
38,992 KB |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); StringBuilder sb = new StringBuilder(sc.next()); int length = sb.length(); boolean result; if (length % 2 == 0) { result = (getResult(sb, length / 2 - 1, length / 2 - 1, true) || getResult(sb, length / 2, length / 2, false)); } else { result = (getResult(sb, length / 2 - 1, length / 2, true) || getResult(sb, length / 2, length / 2 + 1, false)); } if (result) { System.out.println(sb); } else { System.out.println("NA"); } } static boolean getResult(StringBuilder sb, int left, int right, boolean isLeft) { int idx = -1; char ch = (char)0; while (left >= 0 && right < sb.length()) { if (sb.charAt(left) != sb.charAt(right)) { if (idx >= 0) { return false; } if (isLeft) { idx = left + 1; ch = sb.charAt(right); right++; } else { idx = right; ch = sb.charAt(left); left--; } } else { left--; right++; } } if (idx < 0) { if (isLeft) { idx = 0; ch = sb.charAt(sb.length() - 1); } else { idx = sb.length(); ch = sb.charAt(0); } } sb.insert(idx, ch); return true; } }