結果

問題 No.672 最長AB列
ユーザー iwkjoseciwkjosec
提出日時 2018-06-10 10:50:27
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 630 bytes
コンパイル時間 2,826 ms
コンパイル使用メモリ 102,780 KB
実行使用メモリ 32,036 KB
最終ジャッジ日時 2023-09-13 02:35:22
合計ジャッジ時間 6,174 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
22,640 KB
testcase_01 AC 53 ms
22,568 KB
testcase_02 AC 51 ms
20,556 KB
testcase_03 AC 52 ms
22,716 KB
testcase_04 WA -
testcase_05 AC 53 ms
20,724 KB
testcase_06 AC 52 ms
20,588 KB
testcase_07 AC 54 ms
22,488 KB
testcase_08 AC 53 ms
20,596 KB
testcase_09 AC 79 ms
32,036 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 68 ms
19,564 KB
testcase_14 WA -
testcase_15 AC 70 ms
21,464 KB
testcase_16 AC 70 ms
19,688 KB
testcase_17 AC 74 ms
28,564 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;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var S = ReadLine();
        var s = new int[S.Length];
        var dic = new Dictionary<int, int>();
        for (int i = 1; i < s.Length; i++)
        {
            s[i] = s[i - 1] + (S[i] == 'A' ? 1 : -1);
            dic[s[i]] = i;
        }
        var ans = 0;
        for (int i = 0; i < s.Length; i++)
        {
            if (dic.ContainsKey(s[i]))
            {
                ans = Math.Max(ans, dic[s[i]] - i);
            }
        }
        WriteLine(ans);
    }
}
0