結果

問題 No.672 最長AB列
ユーザー uw_yu1rabbituw_yu1rabbit
提出日時 2020-11-27 21:29:07
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,112 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 103,000 KB
実行使用メモリ 51,520 KB
最終ジャッジ日時 2023-10-01 04:45:48
合計ジャッジ時間 5,413 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
47,444 KB
testcase_01 AC 86 ms
49,420 KB
testcase_02 AC 86 ms
47,388 KB
testcase_03 AC 87 ms
51,520 KB
testcase_04 AC 85 ms
47,324 KB
testcase_05 AC 85 ms
48,408 KB
testcase_06 AC 84 ms
47,208 KB
testcase_07 AC 87 ms
49,616 KB
testcase_08 AC 85 ms
47,428 KB
testcase_09 WA -
testcase_10 AC 101 ms
45,484 KB
testcase_11 AC 100 ms
46,276 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 102 ms
45,484 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 100 ms
45,260 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;
            Int32[] sum = new Int32[n + 1];
            for (Int32 i = 0; i < n; i++)
            {
                if (s[i] == 'A') sum[i + 1] = sum[i] + 1;
                else sum[i + 1] = sum[i] - 1;
            }

            var mp = new Dictionary<Int32, (Int32, Int32)>();
            for (Int32 i = -200000; i <= 200000; i++)
            {
                mp.Add(i,(1000,0));
            }

            Int32 ans = 0;
            for (Int32 i = 0; i <= n; i++)
            {
                var (a,b) = mp[sum[i]];
                if (a > i) a = i;
                if (b < i) b = i;
                mp[sum[i]] = (a, b);
                ans = Math.Max(ans, b - a);
            }
            Console.WriteLine(ans);
            /*for (Int32 i = 0; i < n + 1; i++)
            {
                Console.WriteLine(sum[i]);
            }*/
        }
    }
}
0