結果

問題 No.672 最長AB列
ユーザー @abcde@abcde
提出日時 2019-03-18 22:24:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 1,282 ms
コンパイル使用メモリ 144,276 KB
実行使用メモリ 5,116 KB
最終ジャッジ日時 2023-09-26 12:16:51
合計ジャッジ時間 3,491 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,820 KB
testcase_01 AC 3 ms
4,884 KB
testcase_02 AC 3 ms
4,820 KB
testcase_03 AC 2 ms
4,896 KB
testcase_04 AC 3 ms
5,096 KB
testcase_05 AC 3 ms
4,876 KB
testcase_06 AC 3 ms
4,824 KB
testcase_07 AC 2 ms
5,084 KB
testcase_08 AC 3 ms
4,876 KB
testcase_09 AC 6 ms
5,056 KB
testcase_10 AC 7 ms
5,048 KB
testcase_11 AC 6 ms
5,116 KB
testcase_12 AC 7 ms
5,064 KB
testcase_13 AC 7 ms
5,088 KB
testcase_14 AC 7 ms
5,104 KB
testcase_15 AC 7 ms
5,096 KB
testcase_16 AC 7 ms
4,944 KB
testcase_17 AC 7 ms
5,004 KB
testcase_18 AC 7 ms
4,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 解答不能(WAが取れない)と判断したので, 下記, 正解者様のソースを確認後, 再提出.
// https://yukicoder.me/submissions/318987
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5+1;
int A[N];

int main() {
    
    // 1. 入力情報取得.
    string S;
    cin >> S;
    
    // 2. 模範解答通り.
    int ans = 0, n = S.size(), c = n;
    for(int i = 0; i < N; i++) A[i] = n;
    A[n] = -1;
    for(int i = 0; i < n; i++){
        c += (S[i]=='A' ? 1 : -1);
        A[c] = min(A[c], i);
        ans = max(ans, i - A[c]);
    }
    
    // 3. 後処理.
    cout << ans << endl;
    return 0;
    
}
0