結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-16 09:53:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 83 ms / 2,000 ms |
| コード長 | 541 bytes |
| コンパイル時間 | 833 ms |
| コンパイル使用メモリ | 79,140 KB |
| 最終ジャッジ日時 | 2025-01-09 19:25:16 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <iostream>
#include <map>
#include <string>
void solve() {
std::string s;
std::cin >> s;
std::map<int, int> pos;
pos[0] = 0;
int ans = 0, idx = 0, h = 0;
for (char c : s) {
h += (c == 'A' ? 1 : -1);
++idx;
if (pos.count(h)) {
ans = std::max(ans, idx - pos[h]);
} else {
pos[h] = idx;
}
}
std::cout << ans << std::endl;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}