結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2021-04-10 16:46:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 86 ms / 2,000 ms |
コード長 | 488 bytes |
コンパイル時間 | 1,875 ms |
コンパイル使用メモリ | 177,488 KB |
実行使用メモリ | 12,908 KB |
最終ジャッジ日時 | 2024-06-26 05:52:31 |
合計ジャッジ時間 | 3,078 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); map<int,int> mp; int cnt = 0; int ans = 0; mp[0] = -1; for (int i = 0; i < n; i++) { if (s[i] == 'A') cnt++; else cnt--; if (mp.count(cnt)) { ans = max(ans , i - mp[cnt]); //cout << i << " : " << ans << endl; } else { mp[cnt] = i; } } cout << ans << endl; return 0; }