結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-05 05:23:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 375 bytes |
| コンパイル時間 | 2,253 ms |
| コンパイル使用メモリ | 194,316 KB |
| 最終ジャッジ日時 | 2025-01-10 06:40:53 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
string s; cin>>s;
int n=s.length();
vector<int> sum(n+1);
rep(i,n) sum[i+1]=sum[i]+(s[i]=='A'?1:-1);
const int OFS=n;
vector<int> pos(2*n+1,-1);
rep(i,n+1) pos[sum[i]+OFS]=i;
int ans=0;
rep(i,n) ans=max(ans,pos[sum[i]+OFS]-i);
printf("%d\n",ans);
return 0;
}