結果

問題 No.238 Mr. K's Another Gift
ユーザー eitahoeitaho
提出日時 2015-07-07 22:47:12
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 2,690 bytes
コンパイル時間 2,488 ms
コンパイル使用メモリ 106,208 KB
実行使用メモリ 28,676 KB
最終ジャッジ日時 2023-09-22 09:24:02
合計ジャッジ時間 7,722 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
20,608 KB
testcase_01 AC 55 ms
20,632 KB
testcase_02 AC 55 ms
20,524 KB
testcase_03 AC 56 ms
20,640 KB
testcase_04 AC 57 ms
23,088 KB
testcase_05 AC 60 ms
25,732 KB
testcase_06 AC 63 ms
28,564 KB
testcase_07 AC 64 ms
26,872 KB
testcase_08 AC 62 ms
26,724 KB
testcase_09 AC 62 ms
26,788 KB
testcase_10 AC 54 ms
22,564 KB
testcase_11 AC 54 ms
20,624 KB
testcase_12 AC 55 ms
20,660 KB
testcase_13 AC 55 ms
20,576 KB
testcase_14 AC 59 ms
25,820 KB
testcase_15 AC 61 ms
26,164 KB
testcase_16 AC 61 ms
26,372 KB
testcase_17 AC 58 ms
21,792 KB
testcase_18 AC 59 ms
24,360 KB
testcase_19 AC 56 ms
23,452 KB
testcase_20 AC 53 ms
20,404 KB
testcase_21 AC 53 ms
20,408 KB
testcase_22 AC 53 ms
20,528 KB
testcase_23 AC 56 ms
20,556 KB
testcase_24 AC 57 ms
23,036 KB
testcase_25 AC 57 ms
19,516 KB
testcase_26 AC 64 ms
26,652 KB
testcase_27 AC 63 ms
26,848 KB
testcase_28 AC 64 ms
28,676 KB
testcase_29 AC 63 ms
26,868 KB
testcase_30 AC 54 ms
20,520 KB
testcase_31 AC 55 ms
20,616 KB
testcase_32 AC 55 ms
22,592 KB
testcase_33 AC 56 ms
20,908 KB
testcase_34 AC 56 ms
21,300 KB
testcase_35 AC 61 ms
27,256 KB
testcase_36 AC 59 ms
23,580 KB
testcase_37 AC 61 ms
27,480 KB
testcase_38 AC 58 ms
24,900 KB
testcase_39 AC 58 ms
21,332 KB
testcase_40 AC 55 ms
18,504 KB
testcase_41 AC 55 ms
20,628 KB
testcase_42 AC 54 ms
18,464 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

class Program
{
    static readonly string Bad = "NA";

    public void Solve()
    {
        string S = Reader.String();
        var ans = Rec(S, 0, S.Length - 1, false);
        if (S != Bad && ans == S)
            if (ans.Length % 2 == 0) ans = ans.Insert(ans.Length / 2, "a");
            else ans = ans.Insert(ans.Length / 2, ans[ans.Length / 2] + "");
        Console.WriteLine(ans);
    }

    string Rec(string S, int L, int R, bool inserted)
    {
        if (L >= R) return S;
        if (S[L] == S[R]) return Rec(S, L + 1, R - 1, inserted);
        if (inserted) return Bad;
        var insertL = Rec(S.Insert(L, S[R] + ""), L + 1, R, true);
        if (insertL != Bad) return insertL;
        return Rec(S.Insert(R + 1, S[L] + ""), L + 1, R, true);
    }
}



class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    private static TextReader reader = Console.In;
    private static readonly char[] separator = { ' ' };
    private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    private static string[] A = new string[0];
    private static int i;
    private static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); }
    public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); }
    public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Line()).ToArray(); }
    public static string Line() { return reader.ReadLine().Trim(); }
    private static string[] Split(string s) { return s.Split(separator, op); }
    private static string Next() { CheckNext(); return A[i++]; }
    private static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}
0