結果

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

            var count = 0;
            var ans = 0;
            for (var i = 0; i < S.Length; i++)
            {
                count += (S[i] - '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