結果
問題 | No.672 最長AB列 |
ユーザー |
![]() |
提出日時 | 2021-01-04 15:21:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 83 ms / 2,000 ms |
コード長 | 442 bytes |
コンパイル時間 | 2,042 ms |
コンパイル使用メモリ | 200,804 KB |
最終ジャッジ日時 | 2025-01-17 09:35:27 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);string S;cin >> S;const int N = S.size();int cur = 0, res = 0;map<int, int> mp;mp[0] = 0;for (int i = 0; i < N; i++) {cur += S[i] == 'A' ? 1 : -1;if (mp.find(cur) == mp.end()) {mp[cur] = i + 1;} else {res = max(res, i + 1 - mp[cur]);}}cout << res << '\n';return 0;}