結果

問題 No.672 最長AB列
ユーザー PachicobuePachicobue
提出日時 2018-04-13 22:37:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 446 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 82,828 KB
実行使用メモリ 12,784 KB
最終ジャッジ日時 2023-09-10 00:05:16
合計ジャッジ時間 2,030 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,388 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,388 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 85 ms
12,784 KB
testcase_10 AC 62 ms
8,368 KB
testcase_11 AC 56 ms
8,172 KB
testcase_12 AC 13 ms
4,384 KB
testcase_13 AC 13 ms
4,388 KB
testcase_14 AC 13 ms
4,384 KB
testcase_15 AC 13 ms
4,384 KB
testcase_16 AC 13 ms
4,508 KB
testcase_17 AC 61 ms
8,044 KB
testcase_18 AC 7 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
using namespace std;
int main()
{
    map<int, int> left;
    string s;
    cin >> s;
    int ans = 0;
    int maxi = 0;
    left[0] = -1;
    for (int i = 0; i < s.size(); i++) {
        ans += (s[i] == 'A' ? 1 : -1);
        if (left.find(ans) == left.end()) {
            left[ans] = i;
        } else {
            maxi = max(maxi, i - left[ans]);
        }
    }
    cout << maxi << endl;

    return 0;
}
0