結果
| 問題 |
No.2276 I Want AC
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-21 21:28:13 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 632 bytes |
| コンパイル時間 | 617 ms |
| コンパイル使用メモリ | 65,024 KB |
| 実行使用メモリ | 5,372 KB |
| 最終ジャッジ日時 | 2024-11-06 14:56:12 |
| 合計ジャッジ時間 | 2,523 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 56 |
ソースコード
#include<iostream>
using namespace std;
int N;
string S;
int LA[2<<17],RC[2<<17];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>N>>S;
long long base=0;
int hatena=0;
long long add=0;
for(int i=0;i<N;i++)
{
LA[i+1]=LA[i];
if(S[i]=='A')
{
LA[i+1]++;
}
else if(S[i]=='C')
{
base+=LA[i];
}
else
{
hatena++;
add+=LA[i];
}
}
for(int i=N;i--;)
{
RC[i]=RC[i+1];
if(S[i]=='C')RC[i]++;
}
long long plus=add;
int vis=0;
for(int i=0;i<N;i++)if(S[i]=='?')
{
plus-=LA[i];
plus+=RC[i];
vis++;
add=max(add,plus+(long long)vis*(hatena-vis));
}
cout<<base+add<<endl;
}