結果

問題 No.588 空白と回文
ユーザー RisenRisen
提出日時 2017-11-03 22:45:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,157 bytes
コンパイル時間 1,660 ms
コンパイル使用メモリ 101,260 KB
実行使用メモリ 22,648 KB
最終ジャッジ日時 2023-08-14 17:06:12
合計ジャッジ時間 3,669 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
18,488 KB
testcase_01 AC 41 ms
22,460 KB
testcase_02 AC 40 ms
20,492 KB
testcase_03 AC 42 ms
20,440 KB
testcase_04 AC 42 ms
20,392 KB
testcase_05 AC 41 ms
20,616 KB
testcase_06 AC 41 ms
20,560 KB
testcase_07 AC 40 ms
20,424 KB
testcase_08 AC 41 ms
20,596 KB
testcase_09 AC 42 ms
22,540 KB
testcase_10 AC 42 ms
22,552 KB
testcase_11 AC 43 ms
22,640 KB
testcase_12 AC 44 ms
22,540 KB
testcase_13 AC 41 ms
20,700 KB
testcase_14 AC 41 ms
20,596 KB
testcase_15 AC 41 ms
20,436 KB
testcase_16 AC 42 ms
20,480 KB
testcase_17 AC 45 ms
20,588 KB
testcase_18 AC 40 ms
20,580 KB
testcase_19 AC 40 ms
20,488 KB
testcase_20 AC 43 ms
20,496 KB
testcase_21 AC 44 ms
22,648 KB
testcase_22 AC 43 ms
22,448 KB
testcase_23 AC 43 ms
20,520 KB
testcase_24 AC 40 ms
20,492 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 Solution
{
    static void Main()
    {
        var s = Console.ReadLine();
        var bestLen = 0;

        // 中心は文字のケース
        for (int i = 0; i < s.Length; i++)
        {
            int len = 1;
            int left = i - 1;
            int right = i + 1;
            while (left >= 0 && right < s.Length)
            {
                if (s[left] == s[right])
                {
                    len += 2;
                }
                left--;
                right++;
            }

            bestLen = Math.Max(len, bestLen);
        }

        // 中心は文字間のケース
        for (int i = 0; i < s.Length; i++)
        {
            int len = 0;
            int left = i;
            int right = i + 1;
            while (left >= 0 && right < s.Length)
            {
                if (s[left] == s[right])
                {
                    len += 2;
                }
                left--;
                right++;
            }

            bestLen = Math.Max(len, bestLen);
        }
        Console.WriteLine(bestLen);
    }
}
0