結果
| 問題 | No.672 最長AB列 | 
| コンテスト | |
| ユーザー |  misora192 | 
| 提出日時 | 2020-05-21 08:11:24 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,145 bytes | 
| コンパイル時間 | 1,501 ms | 
| コンパイル使用メモリ | 170,016 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-10-01 23:53:38 | 
| 合計ジャッジ時間 | 2,204 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 11 WA * 5 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)
using namespace std;
typedef long long ll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int n;
vector<int> a, b;
bool cond(int x){
	if(2*x > n) return false;
	for(int i = 0; i + 2*x <= n; i++){
		if((a[i+2*x] - a[i]) == (b[i+2*x] - b[i])) return true;
	}
	return false;
}
// condを満たす最大のxを求める(upper_bound)
// 全てのxが条件を満たさない場合は-1を返す(-1はとりえない値)
int upper_bound_cond(){
	int lb = -1, ub = n;
	while(ub - lb > 1){
		int mid = (lb + ub) / 2;
		if(cond(mid)) lb = mid;   // Answer is in [mid, ub)
		else ub = mid;            // Answer is in [lb, mid)
	}
	// now lb + 1 = ub
	return lb;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	n = s.size();
	a.resize(n+1, 0);
	b.resize(n+1, 0);
	rep(i, n){
		a[i+1] = a[i] + (s[i] == 'A' ? 1 : 0);
		b[i+1] = b[i] + (s[i] == 'B' ? 1 : 0);
	}
	cout << max(2 * upper_bound_cond(), 0) << endl;
}
            
            
            
        