結果
問題 |
No.672 最長AB列
|
ユーザー |
|
提出日時 | 2018-04-15 02:53:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 330 bytes |
コンパイル時間 | 1,624 ms |
コンパイル使用メモリ | 175,436 KB |
実行使用メモリ | 13,168 KB |
最終ジャッジ日時 | 2024-06-27 20:12:20 |
合計ジャッジ時間 | 2,713 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int ans = 0, sum = 0; map<int,int> mp; mp[0] = -1; for (int i = 0; i < S.size(); i++) { sum += S[i] == 'A' ? 1 : -1; mp.count(sum) == 0 ? mp[sum] = i : ans = max(ans, i - mp[sum]); } printf("%d\n", ans); return 0; }