結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2019-10-21 17:28:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 76 ms / 2,000 ms |
コード長 | 454 bytes |
コンパイル時間 | 1,624 ms |
コンパイル使用メモリ | 173,836 KB |
実行使用メモリ | 13,692 KB |
最終ジャッジ日時 | 2024-07-02 17:47:36 |
合計ジャッジ時間 | 2,466 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin >> s; int N=s.size(); int cnt[N+2]={}; for(int i=1;i<=N;i++){ if(s[i-1]=='A') cnt[i]++; else cnt[i]--; } for(int i=1;i<=N;i++){ cnt[i]+=cnt[i-1]; } map<int,int> m; for(int i=0;i<=N;i++){ m[cnt[i]]=i; } int ans=0; for(int i=0;i<=N;i++){ ans=max(m[cnt[i]]-i,ans); } cout << ans << endl; }