結果

問題 No.588 空白と回文
ユーザー バカらっくバカらっく
提出日時 2017-11-03 22:55:01
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,274 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 108,672 KB
実行使用メモリ 31,760 KB
最終ジャッジ日時 2024-05-02 05:17:49
合計ジャッジ時間 4,579 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
31,760 KB
testcase_01 AC 30 ms
18,688 KB
testcase_02 AC 29 ms
18,688 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        string inpt = Reader.ReadLine();
        int ans = 0;
        for (int i = 0; i < inpt.Length; i++) {
            ans = Math.Max(ans, GetMaxTaisyo(i, inpt));
        }
        Console.WriteLine(ans);
    }


    private int GetMaxTaisyo(int idx, String target) {
        int ans = 1;

        char[] tmp = target.ToArray();
        for (int i = 1; i < target.Length; i++) {
            int fromIdx = idx - i;
            int toIdx = idx + i;
            if (fromIdx < 0) {
                break;
            }
            if(toIdx >= target.Length) {
                break;
            }
            if(tmp[idx-i]!=tmp[idx+i]) {
                tmp[idx - i] = ' ';
                tmp[idx + i] = ' ';
            }
            ans = Math.Max(ans, tmp.Skip(fromIdx).Take(i * 2 + 1).Count(a => a != ' '));
        }

        tmp = target.ToArray();
        for (int i = 1; i < target.Length; i++) {
            int fromidx = idx - i + 1;
            int toIdx = idx + i;
            if (fromidx < 0)
            {
                break;
            }
            if (toIdx >= target.Length)
            {
                break;
            }
            if(tmp[fromidx] != tmp[toIdx]) {
                tmp[fromidx] = ' ';
                tmp[toIdx] = ' ';
            }
            ans = Math.Max(ans, tmp.Skip(fromidx).Take(i * 2).Count(a => a != ' '));
        }
        return ans;
    }


    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"


1145141919810


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}
0