結果

問題 No.672 最長AB列
ユーザー Esire
提出日時 2018-11-27 19:06:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,174 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 96,360 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-23 22:31:59
合計ジャッジ時間 1,593 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 9
権限があれば一括ダウンロードができます

ソースコード

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 <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <queue>
#include <stack>
#include <tuple>

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 a = (s[0] == 'A' ? 1 : 0), b = (s[0] == 'B' ? 1 : 0), ans = 0, max = 0;
    bool flag = (s[0] == 'A' ? false : true);
    for(int i = 1; i < s.size(); i++){
        if(s[i] == 'A'){
            a = (flag ? 1 : a + 1);
        }
        else{
            b = (flag ? b + 1 : 1);
        }

        ans = min(a, b) * 2;
        if(ans > max) max = ans;
        flag = (s[i] == 'A' ? 0 : 1);
    }

    cout << max << endl;
    return 0;
}
0