結果

問題 No.672 最長AB列
ユーザー AreTrashAreTrash
提出日時 2018-05-04 17:54:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 616 bytes
コンパイル時間 2,464 ms
コンパイル使用メモリ 105,064 KB
実行使用メモリ 34,200 KB
最終ジャッジ日時 2023-09-10 09:45:39
合計ジャッジ時間 4,215 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
22,488 KB
testcase_01 AC 55 ms
22,552 KB
testcase_02 AC 54 ms
20,436 KB
testcase_03 AC 53 ms
22,512 KB
testcase_04 AC 53 ms
22,556 KB
testcase_05 AC 54 ms
20,524 KB
testcase_06 AC 53 ms
20,464 KB
testcase_07 AC 54 ms
22,600 KB
testcase_08 AC 54 ms
22,532 KB
testcase_09 AC 73 ms
34,200 KB
testcase_10 AC 67 ms
25,728 KB
testcase_11 AC 68 ms
25,736 KB
testcase_12 AC 62 ms
20,672 KB
testcase_13 AC 62 ms
22,804 KB
testcase_14 AC 61 ms
20,704 KB
testcase_15 AC 62 ms
22,824 KB
testcase_16 AC 61 ms
20,728 KB
testcase_17 AC 67 ms
25,900 KB
testcase_18 AC 60 ms
20,736 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;

namespace No672
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var dic = new Dictionary<int, int> {[0] = 0};

            var count = 0;
            var ans = 0;
            for (var i = 1; i <= S.Length; i++)
            {
                count += (S[i - 1] - 'A') * 2 - 1;
                if (dic.TryGetValue(count, out var dist)) ans = Math.Max(ans, i - dist);
                else dic.Add(count, i);
            }

            Console.WriteLine(ans);
        }
    }
}
0