結果
問題 | No.672 最長AB列 |
ユーザー |
|
提出日時 | 2018-04-13 22:37:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 95 ms / 2,000 ms |
コード長 | 446 bytes |
コンパイル時間 | 811 ms |
コンパイル使用メモリ | 78,960 KB |
最終ジャッジ日時 | 2025-01-05 10:04:00 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <iostream> #include <map> using namespace std; int main() { map<int, int> left; string s; cin >> s; int ans = 0; int maxi = 0; left[0] = -1; for (int i = 0; i < s.size(); i++) { ans += (s[i] == 'A' ? 1 : -1); if (left.find(ans) == left.end()) { left[ans] = i; } else { maxi = max(maxi, i - left[ans]); } } cout << maxi << endl; return 0; }