結果

問題 No.672 最長AB列
ユーザー ldsyb
提出日時 2018-06-07 13:10:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 498 bytes
コンパイル時間 1,476 ms
コンパイル使用メモリ 167,316 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-30 10:27:08
合計ジャッジ時間 2,236 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int last[2 * n + 1];
    fill(last, last + 2 * n + 1, -1);
    int ans = 0;
    for (int i = 0, j = 0; i < n; i++) {
        if (s[i] == 'A') {
            j++;
        } else {
            j--;
        }
        if (0 <= last[n + j]) {
            ans = max(ans, i - last[n + j]);
        } else {
            last[n + j] = i;
        }
    }
    cout << ans << endl;
    return 0;
}
0