結果

問題 No.672 最長AB列
ユーザー troro_kelptroro_kelp
提出日時 2019-03-10 20:38:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,667 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 95,792 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 19:57:59
合計ジャッジ時間 2,197 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return b.second > a.second;
    }
    return a.first < b.first;
}

double a[11];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(5);

    string s;
    cin >> s;

    int n = s.size();

    int left = 0, right = 0;

    int ans = 0;
    int an = 0, bn = 0;
    for (; left < n; ++left)
    {
        while (right < n)
        {
            if (s[right] == 'A')
            {
                if (abs(an + 1 - bn) <= 1)
                {
                    an++;
                    right++;
                }
                else
                    break;
            }
            else if (s[right] == 'B')
            {
                if (abs(an - (bn + 1)) <= 1)
                {
                    bn++;
                    right++;
                }
                else
                    break;
            }
        }

        ans = max(ans, right - left);

        if (left == right)
            right++;
        else
        {
            if (s[left] == 'A')
                an--;
            else
                bn--;
        }
    }
    cout << ans / 2 * 2 << endl;
    return 0;
}
0