結果

問題 No.672 最長AB列
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2020-11-27 21:35:17
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 669 bytes
コンパイル時間 2,914 ms
コンパイル使用メモリ 103,780 KB
実行使用メモリ 36,192 KB
最終ジャッジ日時 2023-10-01 05:00:54
合計ジャッジ時間 5,542 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
20,592 KB
testcase_01 AC 54 ms
20,448 KB
testcase_02 AC 53 ms
20,536 KB
testcase_03 AC 53 ms
20,540 KB
testcase_04 AC 53 ms
20,584 KB
testcase_05 AC 54 ms
20,496 KB
testcase_06 AC 54 ms
20,468 KB
testcase_07 AC 54 ms
20,608 KB
testcase_08 AC 53 ms
20,488 KB
testcase_09 AC 71 ms
36,192 KB
testcase_10 AC 68 ms
25,840 KB
testcase_11 AC 67 ms
25,776 KB
testcase_12 AC 63 ms
22,872 KB
testcase_13 AC 63 ms
18,724 KB
testcase_14 AC 65 ms
20,748 KB
testcase_15 AC 63 ms
22,680 KB
testcase_16 AC 64 ms
20,876 KB
testcase_17 AC 68 ms
25,848 KB
testcase_18 AC 62 ms
22,696 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.ComponentModel;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            String s = Console.ReadLine();
            Int32 n = s.Length;
            var mp = new Dictionary<Int32,Int32>();
            Int32 p = 0;
            mp[0] = -1;
            Int32 ans = 0;
            for (Int32 i = 0; i < n; i++)
            {
                if (s[i] == 'A') p++;
                else p--;
                if (mp.ContainsKey(p)) ans = Math.Max(ans, i - mp[p]);
                else mp[p] = i;
            }
            Console.WriteLine(ans);
        }
    }
}
0