結果

問題 No.672 最長AB列
ユーザー tktk_snsntktk_snsn
提出日時 2021-03-18 23:31:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 701 bytes
コンパイル時間 1,477 ms
コンパイル使用メモリ 174,668 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-04-28 13:38:32
合計ジャッジ時間 2,773 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 79 ms
13,696 KB
testcase_10 AC 57 ms
8,832 KB
testcase_11 AC 50 ms
8,832 KB
testcase_12 AC 13 ms
5,376 KB
testcase_13 AC 14 ms
5,376 KB
testcase_14 AC 13 ms
5,376 KB
testcase_15 AC 13 ms
5,376 KB
testcase_16 AC 12 ms
5,376 KB
testcase_17 AC 55 ms
8,832 KB
testcase_18 AC 7 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
using namespace std;
using ll = long long;

int main(){
    string s; cin >> s;
    vector<int> cnt(s.size()+1, 0);
    for (int i=0;i<s.size();++i){
        if (s[i]=='A') cnt[i+1]=cnt[i]+1;
        else cnt[i+1]=cnt[i]-1;
    }
    int ans = 0;
    map<int,int> mp;
    for (int i=0; i<s.size()+1; ++i) {
        if (mp.find(cnt[i]) != mp.end()) {
            chmax(ans, i-mp[cnt[i]]);
        }
        else {
            mp[cnt[i]]=i;
        }
    }
    cout << ans << endl;
}
0