結果
問題 | No.672 最長AB列 |
ユーザー |
![]() |
提出日時 | 2021-01-27 01:04:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 89 ms / 2,000 ms |
コード長 | 570 bytes |
コンパイル時間 | 1,872 ms |
コンパイル使用メモリ | 173,388 KB |
実行使用メモリ | 15,360 KB |
最終ジャッジ日時 | 2024-06-23 22:54:16 |
合計ジャッジ時間 | 3,073 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int a[200005]; int b[200005]; int c[200005]; map<int,int> mp; int main(){ string s; cin >> s; int n = s.size(); for(int i = 1; i <= n; i++){ if(s[i-1]=='A'){ a[i] = a[i-1]+1; b[i] = b[i-1]; }else{ a[i] = a[i-1]; b[i] = b[i-1]+1; } } int ans = 0; for(int i = 1; i <= n; i++) c[i] = a[i]-b[i]; for(int i = 0; i <= n; i++){ if(mp.find(c[i])==mp.end()) mp[c[i]] = i; else ans = max(ans, i-mp[c[i]]); } cout << ans << endl; return 0; }