結果

問題 No.672 最長AB列
ユーザー NOSS
提出日時 2018-09-02 18:22:48
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 369 bytes
コンパイル時間 1,490 ms
コンパイル使用メモリ 167,292 KB
実行使用メモリ 12,788 KB
最終ジャッジ日時 2024-10-01 21:15:12
合計ジャッジ時間 2,939 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)

int main() {
    string s;
    cin >> s;
    map<int,int> mp;
    int ans = 0, cnt = 0;
    mp[0] = -1;
    REP(i,s.size()){
        cnt += s[i]=='A'?1:-1;
        if(!mp.count(cnt))mp[cnt] = i;
        ans = max(ans,i-mp[cnt]);
    }
    cout << ans << endl;
    return 0;
}
0