結果

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

ソースコード

diff #
raw source code

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