結果
問題 |
No.672 最長AB列
|
ユーザー |
|
提出日時 | 2020-01-14 23:44:12 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 408 bytes |
コンパイル時間 | 2,216 ms |
コンパイル使用メモリ | 166,748 KB |
実行使用メモリ | 12,908 KB |
最終ジャッジ日時 | 2024-12-27 07:33:29 |
合計ジャッジ時間 | 3,453 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; map<int, int> mp; mp[0] = -1; int now = 0; int ans = 0; for(int i = 0;i < s.size();i++){ now += s[i] == 'A' ? 1 : -1; if(mp.find(now) != mp.end()){ ans = max(ans, i-mp[now]); }else{ mp[now] = i; } } cout << ans << endl; return 0; }