結果

問題 No.672 最長AB列
ユーザー treeonetreeone
提出日時 2018-04-13 22:30:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 1,271 ms
コンパイル使用メモリ 147,260 KB
実行使用メモリ 19,000 KB
最終ジャッジ日時 2023-09-10 00:03:25
合計ジャッジ時間 2,423 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
12,784 KB
testcase_01 AC 7 ms
12,652 KB
testcase_02 AC 6 ms
12,908 KB
testcase_03 AC 7 ms
12,680 KB
testcase_04 AC 6 ms
12,780 KB
testcase_05 AC 6 ms
12,728 KB
testcase_06 AC 7 ms
12,776 KB
testcase_07 AC 7 ms
12,740 KB
testcase_08 AC 7 ms
12,908 KB
testcase_09 AC 22 ms
19,000 KB
testcase_10 AC 19 ms
15,972 KB
testcase_11 AC 19 ms
15,980 KB
testcase_12 AC 12 ms
15,128 KB
testcase_13 AC 13 ms
15,188 KB
testcase_14 AC 12 ms
14,980 KB
testcase_15 AC 12 ms
15,148 KB
testcase_16 AC 13 ms
15,004 KB
testcase_17 AC 19 ms
15,908 KB
testcase_18 AC 11 ms
14,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

vector<int> d[400010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int now = 200000;
    d[now].push_back(0);
    rep(i, 0, s.size()){
        if(s[i] == 'A'){
            now++;
            d[now].push_back(i + 1);
        }else{
            now--;
            d[now].push_back(i + 1);
        }
    }
    int ans = 0;
    rep(i, 200000 - s.size(), 200000 + s.size()){
        if(d[i].size() < 2) continue;
        int tmp = d[i][d[i].size() - 1] - d[i][0];
        chmax(ans, tmp);
    }
    cout << ans << endl;
}
0