結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-05-19 23:42:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 20 ms / 2,000 ms |
| コード長 | 620 bytes |
| コンパイル時間 | 1,525 ms |
| コンパイル使用メモリ | 173,392 KB |
| 実行使用メモリ | 19,072 KB |
| 最終ジャッジ日時 | 2024-09-17 06:36:32 |
| 合計ジャッジ時間 | 2,571 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string S;
cin >> S;
int N = S.size();
int n = N + 5;
vector<vector<int>> pos(n * 2, vector<int>());
int cum = n;
pos[cum].push_back(0);
for (int p = 0; p < N; ++p){
if (S[p] == 'A'){
++cum;
}else{
--cum;
}
pos[cum].push_back(p + 1);
}
int ans = 0;
for (auto &vec: pos){
if (vec.size() > 1){
ans = max(ans, vec[vec.size() - 1] - vec[0]);
}
}
cout << ans << endl;
return 0;
}