結果

問題 No.238 Mr. K's Another Gift
ユーザー htensaihtensai
提出日時 2020-05-12 16:39:49
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,486 bytes
コンパイル時間 2,346 ms
コンパイル使用メモリ 73,768 KB
実行使用メモリ 58,616 KB
最終ジャッジ日時 2023-10-11 16:06:27
合計ジャッジ時間 13,224 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,752 KB
testcase_01 AC 121 ms
55,704 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 217 ms
56,784 KB
testcase_06 WA -
testcase_07 AC 222 ms
56,536 KB
testcase_08 AC 218 ms
56,328 KB
testcase_09 AC 223 ms
56,448 KB
testcase_10 AC 119 ms
55,804 KB
testcase_11 AC 121 ms
55,972 KB
testcase_12 AC 122 ms
55,692 KB
testcase_13 AC 136 ms
55,672 KB
testcase_14 AC 184 ms
56,228 KB
testcase_15 AC 204 ms
56,124 KB
testcase_16 AC 208 ms
56,644 KB
testcase_17 AC 208 ms
56,532 KB
testcase_18 AC 208 ms
56,660 KB
testcase_19 AC 203 ms
56,500 KB
testcase_20 AC 122 ms
55,384 KB
testcase_21 AC 122 ms
55,836 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 220 ms
56,636 KB
testcase_28 AC 224 ms
56,552 KB
testcase_29 AC 222 ms
56,452 KB
testcase_30 AC 121 ms
55,652 KB
testcase_31 AC 123 ms
55,860 KB
testcase_32 AC 127 ms
56,112 KB
testcase_33 AC 139 ms
55,776 KB
testcase_34 AC 204 ms
56,452 KB
testcase_35 AC 202 ms
56,256 KB
testcase_36 AC 205 ms
56,920 KB
testcase_37 AC 208 ms
56,384 KB
testcase_38 AC 203 ms
56,356 KB
testcase_39 AC 200 ms
56,552 KB
testcase_40 AC 120 ms
55,532 KB
testcase_41 AC 121 ms
55,740 KB
testcase_42 AC 120 ms
55,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
	                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;
	}
}
0