結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2020-11-27 21:35:17 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 669 bytes |
コンパイル時間 | 2,248 ms |
コンパイル使用メモリ | 111,928 KB |
実行使用メモリ | 36,292 KB |
最終ジャッジ日時 | 2024-07-26 11:51:37 |
合計ジャッジ時間 | 3,659 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
コンパイルメッセージ
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; 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); } } }