結果

問題 No.672 最長AB列
ユーザー EsireEsire
提出日時 2018-11-27 21:02:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,048 bytes
コンパイル時間 858 ms
コンパイル使用メモリ 104,084 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2023-09-06 13:20:23
合計ジャッジ時間 3,128 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//g++ -std=c++11 -Wall -O2 -o main.exe main.cpp
//g++ -std=c++14 -Wall -O2 -o main.exe main.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <tuple>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>

using namespace std;

#define spc " "
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p_ii;
typedef tuple<int, int, int, int> tup;

bool tupComp(tup &t1, tup &t2){
    return get<2>(t1) > get<2>(t2);
}

//------------------------------------------------------------------------------

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

    int c = 0, ans = 0;
    map<int, int> m;
    m[0] = 0;
    for(int i = 0; i < s.size(); i++){
        c += (s[i] == 'A' ? 1 : -1);
        
        if(c != 0 && m[c] == 0) m[c] = i + 1;
        else{
            ans = max(ans, i + 1 - m[c]);
        }
    }
    cout << ans << endl;

    return 0;
}
0