結果

問題 No.672 最長AB列
ユーザー bluemeganebluemegane
提出日時 2018-09-06 20:28:26
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 613 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 104,192 KB
実行使用メモリ 28,416 KB
最終ジャッジ日時 2024-05-03 04:31:44
合計ジャッジ時間 2,300 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
17,536 KB
testcase_01 AC 24 ms
17,536 KB
testcase_02 AC 24 ms
17,920 KB
testcase_03 AC 24 ms
17,408 KB
testcase_04 WA -
testcase_05 AC 24 ms
17,664 KB
testcase_06 AC 23 ms
17,536 KB
testcase_07 AC 24 ms
17,664 KB
testcase_08 AC 25 ms
17,536 KB
testcase_09 AC 46 ms
28,416 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 35 ms
18,432 KB
testcase_14 WA -
testcase_15 AC 35 ms
18,560 KB
testcase_16 AC 35 ms
18,688 KB
testcase_17 AC 40 ms
23,680 KB
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var sL = s.Length;
        var a = new int[sL];
        for (int i = 0; i < sL; i++)
            a[i] = s[i] == 'A' ? 1 : -1;
        var d = new Dictionary<int, int>();
        var ans = 0;
        d[a[0]] = 0;
        for (int i = 1; i < sL; i++)
        {
            a[i] +=  a[i - 1];
            if (d.ContainsKey(a[i]))
                ans = Math.Max(ans, i - d[a[i]]);
            else d[a[i]] = i;
        }
        Console.WriteLine(ans);
    }
}
0