結果

問題 No.672 最長AB列
ユーザー tactac
提出日時 2019-07-25 20:34:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 960 bytes
コンパイル時間 1,580 ms
コンパイル使用メモリ 167,180 KB
実行使用メモリ 22,128 KB
最終ジャッジ日時 2023-09-15 00:05:35
合計ジャッジ時間 4,445 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
15,856 KB
testcase_01 AC 9 ms
15,852 KB
testcase_02 AC 9 ms
15,836 KB
testcase_03 AC 9 ms
15,836 KB
testcase_04 AC 9 ms
15,836 KB
testcase_05 AC 9 ms
15,892 KB
testcase_06 AC 9 ms
15,852 KB
testcase_07 AC 9 ms
15,852 KB
testcase_08 AC 9 ms
15,840 KB
testcase_09 AC 27 ms
22,128 KB
testcase_10 AC 23 ms
18,984 KB
testcase_11 AC 24 ms
18,980 KB
testcase_12 AC 16 ms
17,140 KB
testcase_13 AC 16 ms
16,964 KB
testcase_14 AC 17 ms
17,136 KB
testcase_15 AC 17 ms
17,124 KB
testcase_16 AC 16 ms
17,004 KB
testcase_17 AC 23 ms
18,984 KB
testcase_18 AC 14 ms
16,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

vector<int> v[500001];
int main() {
    string s;
    cin >> s;
    int table[200001]; fill_n(table, 200001, -1);
    table[0] = 300000;
    v[300000].eb(0);
    rep(i, SZ(s)) {
        if (s[i] == 'A') table[i + 1] = table[i] + 1;
        else table[i + 1] = table[i] - 1;
        v[table[i + 1]].eb(i + 1);
    }
    int ans = 0;
    rep(i, 500001) {
        if (SZ(v[i]) < 2) continue;
        chmax(ans, v[i][SZ(v[i]) - 1] - v[i][0]);
    }
    out(ans);
}
0