結果

問題 No.672 最長AB列
コンテスト
ユーザー vjudge1
提出日時 2026-01-16 14:48:07
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 664 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,786 ms
コンパイル使用メモリ 215,064 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2026-01-16 14:48:11
合計ジャッジ時間 2,750 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
const int n=4e5+7;
int pos[n],a[n],b[n];
int main()
    {
   
    string s;
    cin>>s;
    int N=s.size();
    s=" "+s;
    for(int i=1;i<0;i++)
    {
         a[i]=a[i-1]+(s[i]=='A');
         b[i]=b[i-1]+(s[i]=='B');
    }
    int eps=200000;
    for(int i=1;i<=N;i++)
    {
         pos[i]=N+1;        
    }
    pos[eps]==0;  
    for(int i=1;i<=N;i++)
    {
        int x=a[i]-b[i]+eps;
        if(pos[x]==n+1)pos[x]=i;
    }
    int ans=0;
    for(int r=1;r<=N;r++)
    {
        int x=a[r]-b[r]+eps;
        if(pos[x]<r)
        {
            ans=max(ans,r-pos[x]);
        }
    }
    cin>>ans;
    return 0;
}
0