結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-13 22:54:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 209 ms / 2,000 ms |
| コード長 | 613 bytes |
| コンパイル時間 | 1,733 ms |
| コンパイル使用メモリ | 177,548 KB |
| 実行使用メモリ | 22,912 KB |
| 最終ジャッジ日時 | 2024-06-27 16:31:38 |
| 合計ジャッジ時間 | 3,179 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
int n = s.length();
vector<int> c(n + 1, 0);
map<int, int> l, r;
l[0] = 0;
r[0] = 0;
for (int i = 0; i < n; i++) {
c[i + 1] = c[i] + (s[i] == 'A' ? 1 : -1);
if (l.find(c[i + 1]) == l.end()) {
l[c[i + 1]] = i + 1;
}
r[c[i + 1]] = i + 1;
}
int ans = 0;
for (int i = 0; i <= n; i++) {
ans = max(ans, r[c[i]] - l[c[i]]);
}
cout << ans << endl;
return 0;
}