結果
| 問題 | No.672 最長AB列 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-05 05:20:17 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 403 bytes |
| 記録 | |
| コンパイル時間 | 1,188 ms |
| コンパイル使用メモリ | 211,768 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-09 23:20:55 |
| 合計ジャッジ時間 | 2,229 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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,c=0;
rep(i,n){
ans=max(ans,pos[c+OFS]-i);
c+=(s[i]=='A'?1:-1);
}
printf("%d\n",ans);
return 0;
}