結果
| 問題 | No.672 最長AB列 | 
| コンテスト | |
| ユーザー |  🍮かんプリン | 
| 提出日時 | 2019-03-07 22:00:19 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 8 ms / 2,000 ms | 
| コード長 | 575 bytes | 
| コンパイル時間 | 780 ms | 
| コンパイル使用メモリ | 66,456 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-23 14:52:38 | 
| 合計ジャッジ時間 | 1,256 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
ソースコード
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int c,m=0;
    string s;
    cin >> s;
    vector<int> a(2*s.length()+1,-2);
    a[s.length()] = -1;
    c = 0;
    for(int i = 0; i < (int)s.length(); i++) {
        if (s[i] == 'A') {
            c += 1;
        }
        else {
            c -= 1;
        }
        if (a[c + s.length()] == -2) {
            a[c + s.length()] = i;
        }
        else {
            m = max(m,i - a[c + s.length()]);
        }
    }
    cout << m << endl;
    return 0;
}
            
            
            
        