結果
問題 | No.238 Mr. K's Another Gift |
ユーザー | Grenache |
提出日時 | 2015-07-05 23:34:34 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 136 ms / 2,000 ms |
コード長 | 3,558 bytes |
コンパイル時間 | 3,256 ms |
コンパイル使用メモリ | 82,168 KB |
実行使用メモリ | 45,132 KB |
最終ジャッジ日時 | 2024-07-08 00:30:04 |
合計ジャッジ時間 | 8,222 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
37,168 KB |
testcase_01 | AC | 45 ms
37,148 KB |
testcase_02 | AC | 46 ms
37,296 KB |
testcase_03 | AC | 48 ms
37,164 KB |
testcase_04 | AC | 54 ms
37,644 KB |
testcase_05 | AC | 129 ms
43,528 KB |
testcase_06 | AC | 107 ms
43,392 KB |
testcase_07 | AC | 129 ms
44,600 KB |
testcase_08 | AC | 133 ms
44,520 KB |
testcase_09 | AC | 136 ms
44,440 KB |
testcase_10 | AC | 47 ms
36,752 KB |
testcase_11 | AC | 46 ms
37,280 KB |
testcase_12 | AC | 45 ms
36,700 KB |
testcase_13 | AC | 46 ms
37,020 KB |
testcase_14 | AC | 85 ms
41,168 KB |
testcase_15 | AC | 108 ms
43,776 KB |
testcase_16 | AC | 109 ms
43,428 KB |
testcase_17 | AC | 106 ms
43,112 KB |
testcase_18 | AC | 110 ms
43,984 KB |
testcase_19 | AC | 108 ms
43,532 KB |
testcase_20 | AC | 46 ms
37,152 KB |
testcase_21 | AC | 43 ms
37,032 KB |
testcase_22 | AC | 43 ms
37,252 KB |
testcase_23 | AC | 46 ms
37,060 KB |
testcase_24 | AC | 53 ms
37,604 KB |
testcase_25 | AC | 74 ms
39,300 KB |
testcase_26 | AC | 121 ms
43,156 KB |
testcase_27 | AC | 130 ms
45,132 KB |
testcase_28 | AC | 122 ms
43,044 KB |
testcase_29 | AC | 132 ms
44,852 KB |
testcase_30 | AC | 46 ms
36,736 KB |
testcase_31 | AC | 44 ms
36,944 KB |
testcase_32 | AC | 44 ms
37,148 KB |
testcase_33 | AC | 48 ms
37,088 KB |
testcase_34 | AC | 105 ms
43,416 KB |
testcase_35 | AC | 108 ms
42,976 KB |
testcase_36 | AC | 108 ms
43,696 KB |
testcase_37 | AC | 109 ms
43,776 KB |
testcase_38 | AC | 110 ms
43,192 KB |
testcase_39 | AC | 108 ms
43,388 KB |
testcase_40 | AC | 44 ms
36,848 KB |
testcase_41 | AC | 45 ms
36,928 KB |
testcase_42 | AC | 43 ms
36,628 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); } } }