結果

問題 No.672 最長AB列
ユーザー AreTrash
提出日時 2018-05-04 17:54:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 616 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 109,920 KB
実行使用メモリ 36,044 KB
最終ジャッジ日時 2024-06-28 01:13:07
合計ジャッジ時間 2,204 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
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