結果

問題 No.672 最長AB列
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-05-14 17:57:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 607 bytes
コンパイル時間 1,302 ms
コンパイル使用メモリ 156,088 KB
実行使用メモリ 13,488 KB
最終ジャッジ日時 2023-09-10 20:41:08
合計ジャッジ時間 2,472 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 84 ms
13,488 KB
testcase_10 AC 63 ms
8,680 KB
testcase_11 AC 58 ms
8,636 KB
testcase_12 AC 17 ms
4,380 KB
testcase_13 AC 17 ms
4,380 KB
testcase_14 AC 16 ms
4,380 KB
testcase_15 AC 17 ms
4,376 KB
testcase_16 AC 17 ms
4,376 KB
testcase_17 AC 61 ms
8,628 KB
testcase_18 AC 9 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define i64 long long
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int main(){
    string s;
    cin >> s;
    vector<int> a(s.size());
    rep(i,0,s.size() - 1){
        if(s[i] == 'A') a[i] = 1;
        else a[i] = -1;
    }
    rep(i,1,s.size() - 1){
        a[i] += a[i - 1];
    }

    set<int> st;
    int ans = 0;
    map<int,int> mp;
    mp[0] = -1;
    rep(i,0,s.size() - 1){
        if(mp.count(a[i])){
            ans = max(ans , i - mp[a[i]]);
        }
        else{
            mp[a[i]] = i;
        }
    }

    cout << ans << endl;

}
0