結果
問題 | No.672 最長AB列 |
ユーザー |
![]() |
提出日時 | 2020-11-27 21:27:51 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,135 bytes |
コンパイル時間 | 2,189 ms |
コンパイル使用メモリ | 114,808 KB |
実行使用メモリ | 53,284 KB |
最終ジャッジ日時 | 2024-07-23 22:04:42 |
合計ジャッジ時間 | 3,498 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 WA * 11 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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 + 1]];if (a > i + 1) a = i + 1;if (b < i + 1) b = i + 1;mp[sum[i + 1]] = (a, b);ans = Math.Max(ans, b - a);}Console.WriteLine(ans);/*for (Int32 i = 0; i < n + 1; i++){Console.WriteLine(sum[i]);}*/}}}