結果

問題 No.273 回文分解
ユーザー 14番14番
提出日時 2016-05-10 23:10:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 2,453 bytes
コンパイル時間 2,373 ms
コンパイル使用メモリ 107,292 KB
実行使用メモリ 22,696 KB
最終ジャッジ日時 2023-09-07 19:50:37
合計ジャッジ時間 5,423 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
20,488 KB
testcase_01 AC 50 ms
20,500 KB
testcase_02 AC 51 ms
20,668 KB
testcase_03 AC 51 ms
22,544 KB
testcase_04 AC 51 ms
20,404 KB
testcase_05 AC 51 ms
22,536 KB
testcase_06 AC 52 ms
22,452 KB
testcase_07 AC 52 ms
20,464 KB
testcase_08 AC 51 ms
20,588 KB
testcase_09 AC 52 ms
18,600 KB
testcase_10 AC 51 ms
20,488 KB
testcase_11 AC 51 ms
20,568 KB
testcase_12 AC 51 ms
22,508 KB
testcase_13 AC 52 ms
20,668 KB
testcase_14 AC 51 ms
20,480 KB
testcase_15 AC 51 ms
20,492 KB
testcase_16 AC 51 ms
20,540 KB
testcase_17 AC 52 ms
22,540 KB
testcase_18 AC 51 ms
20,400 KB
testcase_19 AC 51 ms
20,408 KB
testcase_20 AC 52 ms
22,612 KB
testcase_21 AC 51 ms
20,520 KB
testcase_22 AC 50 ms
22,528 KB
testcase_23 AC 51 ms
22,528 KB
testcase_24 AC 51 ms
20,516 KB
testcase_25 AC 51 ms
20,496 KB
testcase_26 AC 52 ms
22,532 KB
testcase_27 AC 52 ms
20,560 KB
testcase_28 AC 52 ms
20,468 KB
testcase_29 AC 51 ms
18,472 KB
testcase_30 AC 52 ms
22,696 KB
testcase_31 AC 52 ms
20,692 KB
testcase_32 AC 52 ms
18,460 KB
testcase_33 AC 51 ms
20,640 KB
testcase_34 AC 51 ms
20,392 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.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int ans = this.GetAns(Reader.ReadLine());
        Console.WriteLine(ans);

    }
    private int GetAns(string inpt) {
        int ans  = 1;
        
        for(int i=0; i<inpt.Length; i++) {
            // i を中央と考えた場合
            int len = 1;
            for(int j=0; i  - j >= 0 && i + j < inpt.Length &&  1 + (j * 2) < inpt.Length; j++) {
                if(inpt[i-j] != inpt[i+j]) {
                    break;
                } else
                {
                    len = 1 + (j * 2);
                }
            }
            ans = Math.Max(ans, len);
            // i を偶数この文字列の左側とした場合
            len = 1;
            if(i < inpt.Length - 1 && inpt[i] == inpt[i+1]) {
                for(int j=0; i-j >= 0 && i+1+j < inpt.Length && 2 + (j * 2) < inpt.Length; j++) {
                    if(inpt[i-j] != inpt[i+1+j]) {
                        break;
                    } else
                    {
                        len = 2 + (j * 2);
                    }
                }
                ans = Math.Max(ans, len);
            }
        }
        return ans;
    }

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


ZZ




 
";
        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