結果

問題 No.588 空白と回文
ユーザー バカらっくバカらっく
提出日時 2017-11-03 22:57:20
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 2,308 bytes
コンパイル時間 912 ms
コンパイル使用メモリ 111,828 KB
実行使用メモリ 22,912 KB
最終ジャッジ日時 2024-05-02 05:18:05
合計ジャッジ時間 2,615 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
18,688 KB
testcase_01 AC 26 ms
18,560 KB
testcase_02 AC 26 ms
18,432 KB
testcase_03 AC 58 ms
22,528 KB
testcase_04 AC 25 ms
18,304 KB
testcase_05 AC 25 ms
18,304 KB
testcase_06 AC 27 ms
18,560 KB
testcase_07 AC 27 ms
18,432 KB
testcase_08 AC 26 ms
18,560 KB
testcase_09 AC 26 ms
18,688 KB
testcase_10 AC 26 ms
18,688 KB
testcase_11 AC 58 ms
22,912 KB
testcase_12 AC 59 ms
22,272 KB
testcase_13 AC 27 ms
18,688 KB
testcase_14 AC 25 ms
18,432 KB
testcase_15 AC 26 ms
18,176 KB
testcase_16 AC 25 ms
18,304 KB
testcase_17 AC 50 ms
22,528 KB
testcase_18 AC 26 ms
18,560 KB
testcase_19 AC 26 ms
18,432 KB
testcase_20 AC 61 ms
22,912 KB
testcase_21 AC 54 ms
22,656 KB
testcase_22 AC 59 ms
22,528 KB
testcase_23 AC 48 ms
22,528 KB
testcase_24 AC 26 ms
18,304 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.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();
        int cnt = 1;
        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] = ' ';
            } else {
                cnt += 2;
            }
            ans = Math.Max(ans, cnt);
        }

        tmp = target.ToArray();
        cnt = 0;
        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] = ' ';
            } else {
                cnt += 2;
            }
            ans = Math.Max(ans, cnt);
        }
        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