結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-05 05:20:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 403 bytes |
| コンパイル時間 | 2,132 ms |
| コンパイル使用メモリ | 194,304 KB |
| 最終ジャッジ日時 | 2025-01-10 06:40:43 |
|
ジャッジサーバーID (参考情報) |
judge1 / 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,c=0;
rep(i,n){
ans=max(ans,pos[c+OFS]-i);
c+=(s[i]=='A'?1:-1);
}
printf("%d\n",ans);
return 0;
}