結果

問題 No.273 回文分解
ユーザー bluemeganebluemegane
提出日時 2020-09-11 15:18:16
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,330 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 61,260 KB
実行使用メモリ 22,664 KB
最終ジャッジ日時 2023-08-26 22:07:23
合計ジャッジ時間 4,239 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
20,600 KB
testcase_01 AC 50 ms
18,560 KB
testcase_02 AC 51 ms
20,452 KB
testcase_03 AC 48 ms
20,476 KB
testcase_04 AC 50 ms
22,632 KB
testcase_05 AC 49 ms
20,736 KB
testcase_06 AC 50 ms
20,480 KB
testcase_07 AC 47 ms
20,520 KB
testcase_08 AC 49 ms
20,412 KB
testcase_09 AC 50 ms
18,376 KB
testcase_10 AC 49 ms
20,568 KB
testcase_11 AC 48 ms
20,624 KB
testcase_12 AC 50 ms
20,416 KB
testcase_13 AC 53 ms
20,560 KB
testcase_14 AC 53 ms
22,544 KB
testcase_15 AC 51 ms
20,476 KB
testcase_16 AC 51 ms
18,532 KB
testcase_17 AC 50 ms
22,448 KB
testcase_18 AC 51 ms
20,620 KB
testcase_19 AC 50 ms
20,552 KB
testcase_20 AC 49 ms
20,564 KB
testcase_21 AC 50 ms
22,664 KB
testcase_22 AC 50 ms
22,516 KB
testcase_23 AC 48 ms
20,596 KB
testcase_24 AC 49 ms
20,704 KB
testcase_25 AC 49 ms
20,616 KB
testcase_26 AC 48 ms
20,536 KB
testcase_27 AC 51 ms
22,656 KB
testcase_28 AC 50 ms
22,532 KB
testcase_29 AC 49 ms
20,532 KB
testcase_30 AC 48 ms
20,580 KB
testcase_31 AC 50 ms
20,572 KB
testcase_32 AC 50 ms
20,712 KB
testcase_33 AC 49 ms
20,488 KB
testcase_34 AC 48 ms
20,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var s = Console.ReadLine().Trim();
        getAns(s);

    }
    static int check2(string s, int p)
    {
        var sL = s.Length;
        var d = 0;
        var count = 0;
        while (true)
        {
            if (p + d + 1 == sL | p - d < 0) break;
            if (s[p - d] == s[p + d + 1])
            {
                count += 2;
                if (count == sL) { count -= 2; break; }
            }
            else break;
            d++;
        }
        return count;
    }
    static int check1(string s, int p)
    {
        var sL = s.Length;
        var d = 1;
        var count = 1;
        while (true)
        {
            if (p + d == sL | p - d < 0) break;
            if (s[p + d] == s[p - d])
            {
                count += 2;
                if (count == sL) { count -= 2; break; }
            }
            else break;
            d++;
        }
        return count;
    }
    static void getAns(string s)
    {
        var sL = s.Length;
        var ans = 1;
        for (int i = 0; i < sL; i++)
        {
            var t0 = check1(s, i);
            var t1 = check2(s, i);
            ans = Max(ans, t0);
            ans = Max(ans, t1);
        }
        Console.WriteLine(ans);
    }
}
0