結果

問題 No.672 最長AB列
ユーザー BantakoBantako
提出日時 2018-05-28 19:53:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 167,048 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2023-09-12 20:13:16
合計ジャッジ時間 2,385 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,312 KB
testcase_01 AC 4 ms
6,168 KB
testcase_02 AC 4 ms
6,348 KB
testcase_03 AC 4 ms
6,460 KB
testcase_04 AC 4 ms
6,168 KB
testcase_05 AC 4 ms
6,312 KB
testcase_06 AC 4 ms
6,220 KB
testcase_07 AC 4 ms
6,320 KB
testcase_08 AC 4 ms
6,208 KB
testcase_09 AC 8 ms
6,576 KB
testcase_10 AC 7 ms
6,592 KB
testcase_11 AC 8 ms
6,644 KB
testcase_12 AC 9 ms
6,648 KB
testcase_13 AC 9 ms
6,656 KB
testcase_14 AC 9 ms
6,640 KB
testcase_15 AC 9 ms
6,588 KB
testcase_16 AC 9 ms
6,592 KB
testcase_17 AC 8 ms
6,592 KB
testcase_18 AC 7 ms
6,588 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    6 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    const int MAX_N = 200000;
    int cnt = MAX_N;
    vector<int> A(MAX_N*2 + 1,INF),B(MAX_N*2 + 1);
    A[cnt] = 0,B[cnt] = 0;
    for(int i = 0;i < S.size();i++){
        if(S[i] == 'A')cnt++;
        else           cnt--;

        A[cnt] = min(A[cnt], i+1);
        B[cnt] = i+1;
    }
    int maxi = 0;
    for(int i = 0;i <= MAX_N*2;i++){
        maxi = max(maxi, B[i] - A[i]);
    }
    cout << maxi << endl;
}
0