結果
| 問題 | No.672 最長AB列 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-04-15 00:15:36 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 84 ms / 2,000 ms | 
| コード長 | 336 bytes | 
| コンパイル時間 | 1,751 ms | 
| コンパイル使用メモリ | 175,724 KB | 
| 実行使用メモリ | 13,040 KB | 
| 最終ジャッジ日時 | 2024-06-27 20:09:33 | 
| 合計ジャッジ時間 | 3,026 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() 
{
  string S;
  cin >> S;
  int ans = 0, sum = 0;
  map<int,int> mp;
  mp[0] = -1;
  for (int i = 0; i < S.size(); i++)
  {
    sum += S[i] == 'A' ? 1 : -1; 
    if (mp.count(sum)) ans = max(ans, i - mp[sum]);
    else mp[sum] = i;
  }
  printf("%d\n", ans);
  return 0;
}
            
            
            
        