結果

問題 No.238 Mr. K's Another Gift
ユーザー 14番14番
提出日時 2016-05-08 21:54:22
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 2,962 bytes
コンパイル時間 1,035 ms
コンパイル使用メモリ 105,472 KB
実行使用メモリ 26,056 KB
最終ジャッジ日時 2024-04-15 13:58:09
合計ジャッジ時間 3,683 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
23,444 KB
testcase_01 AC 24 ms
23,540 KB
testcase_02 AC 24 ms
23,664 KB
testcase_03 AC 24 ms
23,536 KB
testcase_04 AC 24 ms
25,680 KB
testcase_05 AC 26 ms
23,928 KB
testcase_06 AC 26 ms
23,616 KB
testcase_07 AC 27 ms
24,176 KB
testcase_08 AC 27 ms
26,056 KB
testcase_09 AC 26 ms
23,792 KB
testcase_10 AC 24 ms
23,656 KB
testcase_11 AC 24 ms
23,660 KB
testcase_12 AC 24 ms
23,344 KB
testcase_13 AC 24 ms
25,580 KB
testcase_14 AC 25 ms
23,624 KB
testcase_15 AC 26 ms
25,668 KB
testcase_16 AC 25 ms
23,612 KB
testcase_17 AC 26 ms
23,796 KB
testcase_18 AC 26 ms
25,620 KB
testcase_19 AC 25 ms
23,740 KB
testcase_20 AC 24 ms
23,472 KB
testcase_21 AC 24 ms
25,616 KB
testcase_22 AC 25 ms
23,424 KB
testcase_23 AC 25 ms
23,664 KB
testcase_24 AC 24 ms
25,384 KB
testcase_25 AC 24 ms
23,500 KB
testcase_26 AC 26 ms
23,608 KB
testcase_27 AC 26 ms
21,812 KB
testcase_28 AC 25 ms
23,604 KB
testcase_29 AC 26 ms
23,972 KB
testcase_30 AC 24 ms
23,476 KB
testcase_31 AC 24 ms
23,440 KB
testcase_32 AC 24 ms
23,668 KB
testcase_33 AC 24 ms
25,440 KB
testcase_34 AC 25 ms
25,660 KB
testcase_35 AC 25 ms
23,620 KB
testcase_36 AC 25 ms
23,792 KB
testcase_37 AC 25 ms
23,412 KB
testcase_38 AC 25 ms
23,740 KB
testcase_39 AC 25 ms
25,528 KB
testcase_40 AC 24 ms
25,608 KB
testcase_41 AC 23 ms
23,604 KB
testcase_42 AC 24 ms
25,748 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.Collections.Generic;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        string str = Reader.ReadLine();
        string ans = this.GetKaibun(str, true);
        if(ans.Length == 0) {
            ans = "NA";
        }
        Console.WriteLine(ans);
    }
    
    private string GetKaibun(string target, bool canIns) {
        int topIdx = 0;
        int bottomIdx = target.Length - 1;
        while (target[topIdx] == target[bottomIdx] && topIdx < bottomIdx)
        {
            topIdx++;
            bottomIdx--;
        }
        if(target.Length == 1) {
            if(canIns) {
                return target + target;
            } else
            {
                return target;
            }
        }
        if(topIdx >= bottomIdx) {
            return target.Substring(0, topIdx) + target[topIdx] + target.Substring(topIdx);
        } else if(!canIns)
        {
            return string.Empty;
        } else
        {
            string mid = target.Substring(topIdx, bottomIdx + 1 - topIdx);
            string tmp1 = this.GetKaibun(mid.Substring(1), false);
            if(tmp1.Length == 0) {
                tmp1 = this.GetKaibun(mid.Substring(0, mid.Length - 1), false);
                if(tmp1.Length > 0) {
                    mid = mid[mid.Length - 1] + mid;
                }
            } else
            {
                mid = mid + mid[0];
            }
            if(tmp1.Length > 0) {
                if(topIdx == 0) {
                    return mid;
                } else
                {
                    return target.Substring(0,topIdx) + mid + target.Substring(bottomIdx + 1);
                }
            } else
            {
                return string.Empty;
            }
        }
    }


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


dedc

 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        public static int[] GetInt(char delimiter = ' ', bool trim = false)
        {
            string inptStr = ReadLine();
            if (trim)
            {
                inptStr = inptStr.Trim();
            }
            string[] inpt = inptStr.Split(delimiter);
            int[] ret = new int[inpt.Length];
            for (int i = 0; i < inpt.Length; i++)
            {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0