結果

問題 No.238 Mr. K's Another Gift
ユーザー te-sh
提出日時 2016-09-20 13:53:46
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 866 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 111,672 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-12 04:30:58
合計ジャッジ時間 3,554 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

void main()
{
  auto s = readln.chomp;

  writeln(calc(s));
}

string calc(string s)
{
  foreach (i; 0..s.length/2) {
    if (s[i] != s[$-i-1]) {
      auto s2 = s[$-i-1] ~ s[i..$-i];
      if (isKaibun(s2))
        return s[0..i] ~ s2 ~ s[$-i..$];
      auto s3 = s[i..$-i] ~ s[i];
      if (isKaibun(s3))
        return s[0..i] ~ s3 ~ s[$-i..$];
      return "NA";
    }
  }

  if (s.length % 2 == 0)
    return s[0..s.length/2] ~ "a" ~ s[s.length/2..$];
  else
    return s[0..s.length/2] ~ s[s.length/2] ~ s[s.length/2] ~ s[s.length/2+1..$];
}

bool isKaibun(string s)
{
  foreach (i; 0..s.length/2)
    if (s[i] != s[$-i-1]) return false;
  return true;
}
0