結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2019-01-26 16:38:02 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 414 bytes |
コンパイル時間 | 792 ms |
コンパイル使用メモリ | 74,088 KB |
実行使用メモリ | 13,692 KB |
最終ジャッジ日時 | 2024-09-16 05:35:19 |
合計ジャッジ時間 | 1,759 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 6 |
ソースコード
#include<iostream> #include<algorithm> #include<cmath> #include<map> using namespace std; int main() { string S; cin >> S; S="_"+S; int ans=0; int sum[200010]={}; map<int,int> m; for(int i=1;i<S.size();i++) { sum[i]=sum[i-1]; if(S[i]=='A')sum[i]++; else sum[i]--; if(m[sum[i]]==0) { m[sum[i]]=i; } else { ans=max(ans,i-m[sum[i]]); } } cout << ans << endl; return 0; }