結果

問題 No.672 最長AB列
ユーザー mencottonmencotton
提出日時 2018-04-24 17:35:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 801 bytes
コンパイル時間 2,715 ms
コンパイル使用メモリ 102,660 KB
実行使用メモリ 56,832 KB
最終ジャッジ日時 2023-09-10 04:52:57
合計ジャッジ時間 5,293 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
23,376 KB
testcase_01 AC 58 ms
21,320 KB
testcase_02 AC 59 ms
21,176 KB
testcase_03 AC 58 ms
21,212 KB
testcase_04 AC 57 ms
21,168 KB
testcase_05 AC 58 ms
21,328 KB
testcase_06 AC 56 ms
21,164 KB
testcase_07 AC 58 ms
21,224 KB
testcase_08 AC 57 ms
21,348 KB
testcase_09 AC 168 ms
56,832 KB
testcase_10 AC 126 ms
46,512 KB
testcase_11 AC 124 ms
47,308 KB
testcase_12 AC 78 ms
25,968 KB
testcase_13 AC 76 ms
24,260 KB
testcase_14 AC 76 ms
24,440 KB
testcase_15 AC 77 ms
24,004 KB
testcase_16 AC 77 ms
23,968 KB
testcase_17 AC 121 ms
46,276 KB
testcase_18 AC 74 ms
23,960 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;

namespace _672
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<int, List<int>> dic = new Dictionary<int, List<int>>();
            string s = Console.ReadLine() + '?';
            int count = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (!dic.ContainsKey(count)) dic[count] = new List<int>();
                dic[count].Add(i);
                if (s[i] == 'A') count++;
                if (s[i] == 'B') count--;
            }
            int ret = 0;
            foreach (var item in dic)
            {
                ret = Math.Max(ret, item.Value.Max() - item.Value.Min());
            }
            Console.WriteLine(ret);
        }
    }
}
0