結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2019-05-24 19:17:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 134 ms / 2,000 ms |
コード長 | 411 bytes |
コンパイル時間 | 1,724 ms |
コンパイル使用メモリ | 175,812 KB |
実行使用メモリ | 16,128 KB |
最終ジャッジ日時 | 2024-09-17 10:13:05 |
合計ジャッジ時間 | 3,072 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { string s; cin >> s; int N = s.size(); map<int, int> m; int p = 0; m[0] = -1; int ans = 0; for (int i = 0; i < N; i++) { char c = s[i]; if (c == 'A') p++; else p--; if (m.count(p)) ans = max(ans, i - m[p]); if (!m.count(p)) m[p] = i; } cout << ans << endl; return 0; }