結果
| 問題 | No.672 最長AB列 | 
| コンテスト | |
| ユーザー |  iqueue02 | 
| 提出日時 | 2019-11-14 23:38:06 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 86 ms / 2,000 ms | 
| コード長 | 455 bytes | 
| コンパイル時間 | 1,590 ms | 
| コンパイル使用メモリ | 176,328 KB | 
| 実行使用メモリ | 12,908 KB | 
| 最終ジャッジ日時 | 2024-09-22 05:30:33 | 
| 合計ジャッジ時間 | 2,721 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
int main(){
  string s;
  cin >> s;
  int n = sz(s);
  map<int,int> mp;
  mp[0] = -1;
  int res = 0;
  int cnt = 0;
  rep(i,n) {
    if (s[i] == 'A') cnt++;
    else cnt--;
    if (mp.count(cnt)) res = max(res, i - mp[cnt]);
    else mp[cnt] = i;
  }
  cout << res << endl;
  return 0;
}
            
            
            
        