結果

問題 No.672 最長AB列
ユーザー mmn15277198
提出日時 2021-04-10 16:32:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 423 bytes
コンパイル時間 1,675 ms
コンパイル使用メモリ 173,384 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-06-26 05:42:17
合計ジャッジ時間 3,071 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
        }
    }
    cout << ans << endl;
    return 0;
}
0