結果
問題 |
No.238 Mr. K's Another Gift
|
ユーザー |
![]() |
提出日時 | 2020-05-12 16:39:49 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,486 bytes |
コンパイル時間 | 2,407 ms |
コンパイル使用メモリ | 77,652 KB |
実行使用メモリ | 54,304 KB |
最終ジャッジ日時 | 2024-09-13 14:50:02 |
合計ジャッジ時間 | 13,128 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 WA * 9 |
ソースコード
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; } }