結果

問題 No.672 最長AB列
ユーザー kappybar
提出日時 2020-05-06 16:29:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 678 bytes
コンパイル時間 1,807 ms
コンパイル使用メモリ 174,892 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-06-28 18:05:53
合計ジャッジ時間 3,005 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    map<int,int> mp;
    vector<int> cnt(n+1,0);
    rep(i,n) cnt[i+1] = cnt[i] + (s[i]=='A'?1:0);
    rep(i,n+1) cnt[i] = 2*cnt[i] - i;
    int ans = 0;
    rep(i,n+1){
        if(mp.count(cnt[i]) > 0){
            ans = max(ans,i - mp[cnt[i]]);
        }else{
            mp[cnt[i]] = i;
        }
    }
    cout << ans << endl;
    return 0;
}
0