結果

問題 No.672 最長AB列
ユーザー onakaT_TitaionakaT_Titai
提出日時 2018-04-13 23:39:56
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,233 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 106,432 KB
実行使用メモリ 5,268 KB
最終ジャッジ日時 2023-08-20 10:38:36
合計ジャッジ時間 1,836 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,016 KB
testcase_01 AC 3 ms
5,032 KB
testcase_02 AC 3 ms
5,032 KB
testcase_03 AC 3 ms
5,084 KB
testcase_04 AC 3 ms
4,992 KB
testcase_05 AC 3 ms
5,040 KB
testcase_06 AC 3 ms
4,960 KB
testcase_07 AC 3 ms
5,040 KB
testcase_08 AC 3 ms
4,920 KB
testcase_09 AC 8 ms
5,160 KB
testcase_10 AC 8 ms
5,208 KB
testcase_11 AC 7 ms
5,196 KB
testcase_12 AC 8 ms
5,228 KB
testcase_13 AC 8 ms
5,232 KB
testcase_14 AC 8 ms
5,220 KB
testcase_15 AC 7 ms
5,176 KB
testcase_16 AC 8 ms
5,268 KB
testcase_17 AC 7 ms
5,136 KB
testcase_18 AC 7 ms
5,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <string>
#include <cstring> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
//#include <boost/multiprecision/cpp_int.hpp>

#define BIT(a) (1 << (a))

using namespace std;
//using namespace boost::multiprecision;

long long MOD = 1000000007;


long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

char s[200005];
int cnt[400005];

int main(void){
    cin >> s;
    int len = strlen(s);
    int Acnt = 0;
    int ans = 0;
    memset(cnt, -1, sizeof(cnt));
    cnt[200000] = 0;
    for (int i = 0; i < len; i++){
        if (s[i] == 'A'){
            ++Acnt;
        }
        if (s[i] == 'B'){
            --Acnt;
        }
        if (cnt[Acnt+200000] == -1){
            cnt[Acnt+200000] = i+1;
        }else{
            if (ans < i+1-cnt[Acnt+200000]) ans = i+1 - cnt[Acnt+200000];
        }
    }
    cout << ans << endl;
    return 0;
}
0