結果
| 問題 | No.672 最長AB列 | 
| コンテスト | |
| ユーザー |  onakaT_Titai | 
| 提出日時 | 2018-04-13 23:39:56 | 
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 7 ms / 2,000 ms | 
| コード長 | 1,233 bytes | 
| コンパイル時間 | 1,034 ms | 
| コンパイル使用メモリ | 141,696 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-30 12:16:33 | 
| 合計ジャッジ時間 | 1,757 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 | 
ソースコード
#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;
}
            
            
            
        