結果
| 問題 | No.672 最長AB列 | 
| コンテスト | |
| ユーザー |  mmn15277198 | 
| 提出日時 | 2021-04-10 16:37:51 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 493 bytes | 
| コンパイル時間 | 1,723 ms | 
| コンパイル使用メモリ | 173,484 KB | 
| 実行使用メモリ | 12,916 KB | 
| 最終ジャッジ日時 | 2024-06-26 05:46:33 | 
| 合計ジャッジ時間 | 2,940 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 14 WA * 2 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    int n = s.size();
    map<int,int> mp;
    int cnt = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A') cnt++;
        else cnt--;
        if (mp.count(cnt)) {
            ans = max(ans , i - mp[cnt]);
        } else { 
            mp[cnt] = i;
        }
    }
    if (cnt == 0) {
        cout << n << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}
            
            
            
        