結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-20 15:45:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 586 bytes |
| コンパイル時間 | 1,602 ms |
| コンパイル使用メモリ | 168,932 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-01 23:35:12 |
| 合計ジャッジ時間 | 4,316 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 RE * 2 |
| other | AC * 3 WA * 2 RE * 11 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define REP(a, b, n) for(int i = a; i < b; i++)
using lint = long long;
signed main(){
string s; cin >> s;
int n = s.size();
vector<int> data(n + 1, 0);
rep(i, n){
if(s[i] == 'A') data[i + 1] = data[i] + 1;
else data[i + 1] = data[i] - 1;
}
int lim = *max_element(data.begin(), data.end());
vector<int> memo(lim + 1, 0);
int ans = 0;
for(int i = 0; i <= n; i++){
int x = data[i];
if(memo[x] == 0) memo[x] = i;
else ans = max(ans, i - memo[x]);
}
cout << ans << endl;
}