結果

問題 No.672 最長AB列
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2018-04-13 22:48:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 745 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 81,508 KB
実行使用メモリ 5,308 KB
最終ジャッジ日時 2023-09-10 00:06:38
合計ジャッジ時間 1,670 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,900 KB
testcase_01 AC 3 ms
4,860 KB
testcase_02 AC 3 ms
4,956 KB
testcase_03 AC 2 ms
4,900 KB
testcase_04 AC 2 ms
4,960 KB
testcase_05 AC 2 ms
4,964 KB
testcase_06 AC 2 ms
5,076 KB
testcase_07 AC 2 ms
4,932 KB
testcase_08 AC 2 ms
4,856 KB
testcase_09 AC 7 ms
5,080 KB
testcase_10 AC 6 ms
5,092 KB
testcase_11 AC 7 ms
5,064 KB
testcase_12 AC 7 ms
4,992 KB
testcase_13 AC 7 ms
5,040 KB
testcase_14 AC 7 ms
5,032 KB
testcase_15 AC 7 ms
5,052 KB
testcase_16 AC 7 ms
5,088 KB
testcase_17 AC 6 ms
5,136 KB
testcase_18 AC 6 ms
5,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int A[200001*2];

int main() {
    string S;
    cin >> S;
    int N = S.length();
    
    fill( A, A+200001*2, -1 );

    int a = 200000;
    A[200000] = 0;
    int ans = 0;
    for ( int i = 1; i <= N; i++ ) {
        if ( S[i-1] == 'A' ) { a++; }
        else { a--; }

        if ( A[a] != -1 ) {
            ans = max( ans, i-A[a] );            
        }
        else {
            A[a] = i;
        }
    }
    cout << ans << endl;
    return 0;
}
0