結果
| 問題 | No.672 最長AB列 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-05-03 20:09:15 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 83 ms / 2,000 ms | 
| コード長 | 507 bytes | 
| コンパイル時間 | 1,722 ms | 
| コンパイル使用メモリ | 167,040 KB | 
| 実行使用メモリ | 12,800 KB | 
| 最終ジャッジ日時 | 2024-06-28 00:48:47 | 
| 合計ジャッジ時間 | 2,862 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
ソースコード
#include "bits/stdc++.h"
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
using namespace std;
int main() {
    fastcin;
    string S;
    cin >> S;
    int l = S.length(), c = 0, ans = 0;
    map<int, int> m;
    m[0] = 0;
    for(int i = 0; i < l; i++) {
        if(S[i]=='A') c++;
        else if(S[i]=='B') c--;
        if(m.find(c)==m.end()) m[c] = i+1;
        else {
            if(ans < (i+1 - m[c])) ans = i+1 - m[c];
        }
    }
    cout << ans << "\n";
    return 0;
}
            
            
            
        