結果
問題 | No.238 Mr. K's Another Gift |
ユーザー | Grenache |
提出日時 | 2015-07-06 10:21:21 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 115 ms / 2,000 ms |
コード長 | 2,937 bytes |
コンパイル時間 | 3,547 ms |
コンパイル使用メモリ | 79,460 KB |
実行使用メモリ | 40,448 KB |
最終ジャッジ日時 | 2024-07-08 01:17:32 |
合計ジャッジ時間 | 8,378 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
37,316 KB |
testcase_01 | AC | 49 ms
37,052 KB |
testcase_02 | AC | 49 ms
37,188 KB |
testcase_03 | AC | 50 ms
37,120 KB |
testcase_04 | AC | 51 ms
37,224 KB |
testcase_05 | AC | 104 ms
40,076 KB |
testcase_06 | AC | 100 ms
39,568 KB |
testcase_07 | AC | 107 ms
40,232 KB |
testcase_08 | AC | 108 ms
39,896 KB |
testcase_09 | AC | 112 ms
40,448 KB |
testcase_10 | AC | 51 ms
36,908 KB |
testcase_11 | AC | 50 ms
37,120 KB |
testcase_12 | AC | 48 ms
37,220 KB |
testcase_13 | AC | 51 ms
36,732 KB |
testcase_14 | AC | 88 ms
38,952 KB |
testcase_15 | AC | 101 ms
40,404 KB |
testcase_16 | AC | 102 ms
40,276 KB |
testcase_17 | AC | 83 ms
39,356 KB |
testcase_18 | AC | 89 ms
39,328 KB |
testcase_19 | AC | 89 ms
39,552 KB |
testcase_20 | AC | 50 ms
37,052 KB |
testcase_21 | AC | 48 ms
36,924 KB |
testcase_22 | AC | 51 ms
36,980 KB |
testcase_23 | AC | 53 ms
37,332 KB |
testcase_24 | AC | 58 ms
37,296 KB |
testcase_25 | AC | 64 ms
37,740 KB |
testcase_26 | AC | 98 ms
39,592 KB |
testcase_27 | AC | 115 ms
40,340 KB |
testcase_28 | AC | 96 ms
39,708 KB |
testcase_29 | AC | 113 ms
40,380 KB |
testcase_30 | AC | 50 ms
36,844 KB |
testcase_31 | AC | 48 ms
37,060 KB |
testcase_32 | AC | 48 ms
37,284 KB |
testcase_33 | AC | 52 ms
36,976 KB |
testcase_34 | AC | 83 ms
39,064 KB |
testcase_35 | AC | 99 ms
40,104 KB |
testcase_36 | AC | 95 ms
39,632 KB |
testcase_37 | AC | 101 ms
40,116 KB |
testcase_38 | AC | 92 ms
39,328 KB |
testcase_39 | AC | 86 ms
39,360 KB |
testcase_40 | AC | 49 ms
37,112 KB |
testcase_41 | AC | 49 ms
37,072 KB |
testcase_42 | AC | 49 ms
36,940 KB |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Iterator; public class Main_yukicoder238_1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); char[] s = sc.next().toCharArray(); int n = s.length; int offset; for (offset = 0; offset < n; offset++) { if (s[offset] != s[n - 1 - offset]) { break; } } if (offset == n) { StringBuilder ret = new StringBuilder(); int len = (n + 1) / 2; ret.append(s, 0, len); ret.append(s[len - 1]); ret.append(s, len, n - len); pr.println(ret); } else { StringBuilder ret = new StringBuilder(); ret.append(s); ret.insert(offset, s[n - 1 - offset]); boolean res = true; for (int i = 0; i < ret.length(); i++) { if (ret.charAt(i) != ret.charAt(ret.length() - 1 - i)) { res = false; break; } } if (res) { pr.println(ret); } else { ret = new StringBuilder(); ret.append(s); ret.insert(n - offset, s[offset]); res = true; for (int i = 0; i < ret.length(); i++) { if (ret.charAt(i) != ret.charAt(ret.length() - 1 - i)) { res = false; break; } } if (res) { pr.println(ret); } else { pr.println("NA"); } } } pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }