結果
問題 |
No.2276 I Want AC
|
ユーザー |
|
提出日時 | 2023-07-07 21:25:07 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 1,164 bytes |
コンパイル時間 | 4,788 ms |
コンパイル使用メモリ | 112,132 KB |
実行使用メモリ | 28,672 KB |
最終ジャッジ日時 | 2024-07-21 17:05:56 |
合計ジャッジ時間 | 8,703 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var s = ReadLine(); var sc = s.Replace('?', 'C'); var acount = 0; var tmp = 0L; for (var i = 0; i < n; ++i) { if (sc[i] == 'A') ++acount; else tmp += acount; } var ccount = new int[n]; for (var i = n - 1; i >= 0; --i) { if (i < n - 1) ccount[i] = ccount[i + 1]; if (sc[i] != 'A') ++ccount[i]; } acount = 0; var max = tmp; for (var i = 0; i < n; ++i) { if (s[i] == 'A') ++acount; if (s[i] == '?') { tmp = tmp - acount + ccount[i] - 1; ++acount; max = Math.Max(max, tmp); } } WriteLine(max); } }