結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-06-22 16:19:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 90 ms / 2,000 ms |
| コード長 | 514 bytes |
| コンパイル時間 | 770 ms |
| コンパイル使用メモリ | 84,752 KB |
| 実行使用メモリ | 25,344 KB |
| 最終ジャッジ日時 | 2024-06-30 17:59:18 |
| 合計ジャッジ時間 | 2,140 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int main(){
string S;
cin >> S;
map<int, vector<int>> AB;
int depth = 0;
AB[depth].push_back(-1);
for(int i = 0; i < S.size(); i++){
if(S[i] == 'A'){
depth++;
}else{
depth--;
}
AB[depth].push_back(i);
}
int ans = 0;
for(auto i: AB){
ans = max(ans, i.second.back() - i.second.front());
}
cout << ans << endl;
}