結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-13 22:33:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 712 bytes |
| コンパイル時間 | 2,368 ms |
| コンパイル使用メモリ | 204,428 KB |
| 最終ジャッジ日時 | 2025-01-05 10:03:26 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
string S;
cin >> S;
vector<int> pa(S.size() + 1), pb(S.size() + 1);
map<int, int> minpos, maxpos;
minpos[0] = maxpos[0] = 0;
for (int i = 0; i < S.size(); ++i) {
pa[i + 1] = pa[i] + (S[i] == 'A');
pb[i + 1] = pb[i] + (S[i] == 'B');
int d = pa[i + 1] - pb[i + 1];
if (minpos.count(d)) minpos[d] = min(minpos[d], i);
else minpos[d] = i;
maxpos[d] = max(maxpos[d], i);
}
int ans = 0;
for (auto it = minpos.begin(); it != minpos.end(); ++it) {
if (maxpos.count(it->first)) {
ans = max(ans, maxpos[it->first] - it->second);
}
}
cout << ans << endl;
return 0;
}