結果

問題 No.672 最長AB列
ユーザー Y17Y17
提出日時 2020-01-14 23:44:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 408 bytes
コンパイル時間 2,974 ms
コンパイル使用メモリ 153,304 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2023-08-27 12:29:53
合計ジャッジ時間 3,722 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 82 ms
12,672 KB
testcase_10 AC 60 ms
7,980 KB
testcase_11 AC 56 ms
7,944 KB
testcase_12 AC 11 ms
4,380 KB
testcase_13 AC 12 ms
4,384 KB
testcase_14 AC 12 ms
4,376 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 12 ms
4,380 KB
testcase_17 AC 60 ms
7,956 KB
testcase_18 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    string s;
    cin >> s;

    map<int, int> mp;
    mp[0] = -1;
    int now = 0;
    int ans = 0;
    for(int i = 0;i < s.size();i++){
        now += s[i] == 'A' ? 1 : -1;
        if(mp.find(now) != mp.end()){
            ans = max(ans, i-mp[now]);
        }else{
            mp[now] = i;
        }
    }

    cout << ans << endl;
    return 0;
}
0