結果
| 問題 | No.672 最長AB列 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-09-30 00:07:34 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 80 ms / 2,000 ms | 
| コード長 | 491 bytes | 
| コンパイル時間 | 956 ms | 
| コンパイル使用メモリ | 102,092 KB | 
| 実行使用メモリ | 12,800 KB | 
| 最終ジャッジ日時 | 2024-10-03 04:44:33 | 
| 合計ジャッジ時間 | 2,369 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
ソースコード
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main() {
  string s;
  cin >> s;
  int ans=0,cnt=0;
  map<int,int> m;
  m[0]=-1;
  for(int i=0; i<s.size(); i++) {
    if(s[i]=='A') {
      cnt++;
    }
    else {
      cnt--;
    }
    if(m.count(cnt)) {
      ans=max(ans,i-m[cnt]);
    }
    else {
      m[cnt]=i;
    }
  }
  cout << ans << endl;
}
            
            
            
        