結果
問題 | No.238 Mr. K's Another Gift |
ユーザー | Grenache |
提出日時 | 2015-07-05 23:34:34 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 158 ms / 2,000 ms |
コード長 | 3,558 bytes |
コンパイル時間 | 4,405 ms |
コンパイル使用メモリ | 76,736 KB |
実行使用メモリ | 56,496 KB |
最終ジャッジ日時 | 2023-09-22 08:05:55 |
合計ジャッジ時間 | 10,937 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 51 ms
49,216 KB |
testcase_01 | AC | 50 ms
49,164 KB |
testcase_02 | AC | 50 ms
49,452 KB |
testcase_03 | AC | 54 ms
49,336 KB |
testcase_04 | AC | 63 ms
50,188 KB |
testcase_05 | AC | 137 ms
55,996 KB |
testcase_06 | AC | 134 ms
54,956 KB |
testcase_07 | AC | 158 ms
55,616 KB |
testcase_08 | AC | 157 ms
55,484 KB |
testcase_09 | AC | 158 ms
55,412 KB |
testcase_10 | AC | 50 ms
49,736 KB |
testcase_11 | AC | 50 ms
49,584 KB |
testcase_12 | AC | 50 ms
49,484 KB |
testcase_13 | AC | 52 ms
49,324 KB |
testcase_14 | AC | 120 ms
54,748 KB |
testcase_15 | AC | 130 ms
54,616 KB |
testcase_16 | AC | 128 ms
55,320 KB |
testcase_17 | AC | 130 ms
55,056 KB |
testcase_18 | AC | 131 ms
56,496 KB |
testcase_19 | AC | 127 ms
55,332 KB |
testcase_20 | AC | 50 ms
49,264 KB |
testcase_21 | AC | 53 ms
49,596 KB |
testcase_22 | AC | 50 ms
49,284 KB |
testcase_23 | AC | 54 ms
49,388 KB |
testcase_24 | AC | 67 ms
51,224 KB |
testcase_25 | AC | 84 ms
50,748 KB |
testcase_26 | AC | 141 ms
54,928 KB |
testcase_27 | AC | 158 ms
55,264 KB |
testcase_28 | AC | 141 ms
55,876 KB |
testcase_29 | AC | 154 ms
55,284 KB |
testcase_30 | AC | 49 ms
49,212 KB |
testcase_31 | AC | 48 ms
49,320 KB |
testcase_32 | AC | 51 ms
49,444 KB |
testcase_33 | AC | 60 ms
50,456 KB |
testcase_34 | AC | 125 ms
55,216 KB |
testcase_35 | AC | 126 ms
55,472 KB |
testcase_36 | AC | 128 ms
55,420 KB |
testcase_37 | AC | 131 ms
55,160 KB |
testcase_38 | AC | 125 ms
54,844 KB |
testcase_39 | AC | 129 ms
54,564 KB |
testcase_40 | AC | 52 ms
49,312 KB |
testcase_41 | AC | 51 ms
49,312 KB |
testcase_42 | AC | 51 ms
49,588 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.ArrayDeque; import java.util.Arrays; import java.util.Iterator; import java.util.Queue; public class Main_yukicoder238 { 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; Queue<Character> fq = new ArrayDeque<Character>(); Queue<Character> rq = new ArrayDeque<Character>(); boolean flag = false; for (int i = 0; i < n; i++) { if (!flag && s[i] != s[n - 1 - i]) { rq.add(s[i]); fq.add(s[n - 1 - i]); flag = true; } fq.add(s[i]); rq.add(s[n - 1 - i]); } if (!flag) { StringBuilder ret = new StringBuilder(); int len = (n + 1) / 2; for (int i = 0; i < len; i++) { ret.append(s[i]); } ret.append(s[len - 1]); for (int i = len; i < n; i++) { ret.append(s[i]); } pr.println(ret); } else { Character[] tmp = new Character[0]; tmp = fq.toArray(tmp); boolean res = true; for (int i = 0; i < tmp.length; i++) { if (tmp[i] != tmp[tmp.length - 1 - i]) { res = false; break; } } if (res) { StringBuilder ret = new StringBuilder(); for (int i = 0; i < tmp.length; i++) { ret.append(tmp[i]); } pr.println(ret); pr.close(); sc.close(); return; } Character[] tmp2 = new Character[0]; tmp2 = rq.toArray(tmp2); boolean res2 = true; for (int i = 0; i < tmp2.length; i++) { if (tmp2[i] != tmp2[tmp2.length - 1 - i]) { res2 = false; break; } } if (res2) { StringBuilder ret = new StringBuilder(); for (int i = 0; i < tmp2.length; i++) { ret.append(tmp2[i]); } 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); } } }