結果

問題 No.672 最長AB列
ユーザー EsireEsire
提出日時 2018-11-27 19:06:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,174 bytes
コンパイル時間 895 ms
コンパイル使用メモリ 93,208 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-06 03:41:07
合計ジャッジ時間 1,850 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 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,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 6 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 6 ms
4,380 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

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