結果

問題 No.672 最長AB列
ユーザー ミドリムシミドリムシ
提出日時 2018-06-22 16:19:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 514 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 85,312 KB
実行使用メモリ 25,320 KB
最終ジャッジ日時 2023-09-13 07:58:49
合計ジャッジ時間 2,320 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 89 ms
25,320 KB
testcase_10 AC 62 ms
14,320 KB
testcase_11 AC 58 ms
14,252 KB
testcase_12 AC 14 ms
4,648 KB
testcase_13 AC 15 ms
4,628 KB
testcase_14 AC 14 ms
4,724 KB
testcase_15 AC 14 ms
4,652 KB
testcase_16 AC 15 ms
4,608 KB
testcase_17 AC 57 ms
14,312 KB
testcase_18 AC 8 ms
4,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main(){
    string S;
    cin >> S;
    map<int, vector<int>> AB;
    int depth = 0;
    AB[depth].push_back(-1);
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'A'){
            depth++;
        }else{
            depth--;
        }
        AB[depth].push_back(i);
    }
    int ans = 0;
    for(auto i: AB){
        ans = max(ans, i.second.back() - i.second.front());
    }
    cout << ans << endl;
}
0