結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2018-04-24 17:35:48 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 134 ms / 2,000 ms |
コード長 | 801 bytes |
コンパイル時間 | 846 ms |
コンパイル使用メモリ | 113,172 KB |
実行使用メモリ | 52,916 KB |
最終ジャッジ日時 | 2024-06-27 20:32:33 |
合計ジャッジ時間 | 2,570 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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.Linq; namespace _672 { class Program { static void Main(string[] args) { Dictionary<int, List<int>> dic = new Dictionary<int, List<int>>(); string s = Console.ReadLine() + '?'; int count = 0; for (int i = 0; i < s.Length; i++) { if (!dic.ContainsKey(count)) dic[count] = new List<int>(); dic[count].Add(i); if (s[i] == 'A') count++; if (s[i] == 'B') count--; } int ret = 0; foreach (var item in dic) { ret = Math.Max(ret, item.Value.Max() - item.Value.Min()); } Console.WriteLine(ret); } } }