結果

問題 No.672 最長AB列
ユーザー gt_ham_bassgt_ham_bass
提出日時 2018-04-14 12:04:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 399 bytes
コンパイル時間 1,390 ms
コンパイル使用メモリ 144,220 KB
実行使用メモリ 8,860 KB
最終ジャッジ日時 2023-09-10 04:24:41
合計ジャッジ時間 5,092 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,860 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int c,n,ans,p[210000];

int main(){
	string s;
	cin >> s;
	
	n = s.size();
	for(int i = 0; i < n; i++){	
		if(s[i] == 'A'){
			c++;
			p[i] = c;
		}
		else if(s[i] == 'B'){
			c--;
			p[i] = c;
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; i+j < n; j++){
			if(p[i] == p[i+j]) ans = max(ans,j);
		}
	}
	cout << ans << endl;
}
0