結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2018-09-06 20:28:26 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 613 bytes |
コンパイル時間 | 862 ms |
コンパイル使用メモリ | 111,580 KB |
実行使用メモリ | 31,628 KB |
最終ジャッジ日時 | 2024-11-24 01:36:10 |
合計ジャッジ時間 | 2,387 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 6 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System.Collections.Generic; using System; public class Hello { public static void Main() { var s = Console.ReadLine().Trim(); var sL = s.Length; var a = new int[sL]; for (int i = 0; i < sL; i++) a[i] = s[i] == 'A' ? 1 : -1; var d = new Dictionary<int, int>(); var ans = 0; d[a[0]] = 0; for (int i = 1; i < sL; i++) { a[i] += a[i - 1]; if (d.ContainsKey(a[i])) ans = Math.Max(ans, i - d[a[i]]); else d[a[i]] = i; } Console.WriteLine(ans); } }