結果

問題 No.238 Mr. K's Another Gift
ユーザー ぴろずぴろず
提出日時 2015-07-05 22:53:22
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,222 bytes
コンパイル時間 2,520 ms
コンパイル使用メモリ 76,468 KB
実行使用メモリ 60,632 KB
最終ジャッジ日時 2023-09-22 06:56:01
合計ジャッジ時間 12,514 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,836 KB
testcase_01 AC 119 ms
55,608 KB
testcase_02 AC 118 ms
55,512 KB
testcase_03 AC 123 ms
55,620 KB
testcase_04 WA -
testcase_05 AC 256 ms
59,260 KB
testcase_06 WA -
testcase_07 AC 259 ms
59,256 KB
testcase_08 AC 258 ms
60,632 KB
testcase_09 AC 265 ms
59,956 KB
testcase_10 AC 116 ms
55,820 KB
testcase_11 AC 115 ms
55,608 KB
testcase_12 AC 117 ms
55,636 KB
testcase_13 AC 133 ms
55,916 KB
testcase_14 AC 199 ms
58,628 KB
testcase_15 AC 230 ms
58,348 KB
testcase_16 AC 240 ms
58,816 KB
testcase_17 AC 207 ms
59,384 KB
testcase_18 AC 208 ms
58,928 KB
testcase_19 AC 220 ms
58,644 KB
testcase_20 AC 117 ms
55,324 KB
testcase_21 AC 117 ms
55,536 KB
testcase_22 AC 118 ms
55,828 KB
testcase_23 AC 124 ms
55,604 KB
testcase_24 AC 157 ms
55,616 KB
testcase_25 AC 160 ms
55,852 KB
testcase_26 AC 247 ms
59,416 KB
testcase_27 AC 264 ms
59,540 KB
testcase_28 AC 243 ms
58,724 KB
testcase_29 AC 259 ms
59,436 KB
testcase_30 AC 115 ms
55,768 KB
testcase_31 AC 118 ms
55,932 KB
testcase_32 AC 120 ms
55,752 KB
testcase_33 AC 139 ms
56,360 KB
testcase_34 AC 213 ms
58,804 KB
testcase_35 AC 232 ms
58,376 KB
testcase_36 AC 221 ms
58,848 KB
testcase_37 AC 228 ms
60,620 KB
testcase_38 AC 219 ms
59,432 KB
testcase_39 AC 215 ms
58,816 KB
testcase_40 AC 116 ms
55,636 KB
testcase_41 AC 116 ms
55,596 KB
testcase_42 AC 117 ms
55,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no238;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		ArrayList<Character> ans = solve(s);
		if (ans == null) {
			System.out.println("NA");
		}else{
			StringBuilder sb = new StringBuilder();
			for(char c:ans) {
				sb.append(c);
			}
			System.out.println(sb.toString());
		}
	}

	public static ArrayList<Character> solve(String s) {
		int n = s.length();
		ArrayList<Character> a = new ArrayList<>();
		for(int i=0;i<n;i++) {
			a.add(s.charAt(i));
		}
		if (isKaibun(a)) {
			a.add(n/2, 'a');
			return a;
		}
		ArrayList<Character> b = new ArrayList<>(a);
		Collections.reverse(b);
		for(int i=0;i<n;i++) {
			char c1 = a.get(i);
			char c2 = b.get(i);
			if (c1 != c2) {
				a.add(i,c2);
				if (isKaibun(a)) {
					return a;
				}
				b.add(i,c1);
				if (isKaibun(b)) {
					return b;
				}
				return null;
			}
		}
		return null; //unreachable
	}

	public static boolean isKaibun(ArrayList<Character> a) {
		int n = a.size();
		for(int i=0;i<n/2;i++) {
			if (a.get(i) != a.get(n-1-i)) {
				return false;
			}
		}
		return true;
	}

}
0