結果

問題 No.238 Mr. K's Another Gift
コンテスト
ユーザー te-sh
提出日時 2016-09-20 13:53:46
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 866 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 573 ms
コンパイル使用メモリ 93,772 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2026-03-05 07:43:32
合計ジャッジ時間 2,400 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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