結果
問題 | No.672 最長AB列 |
ユーザー |
![]() |
提出日時 | 2018-04-13 22:25:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 95 ms / 2,000 ms |
コード長 | 507 bytes |
コンパイル時間 | 1,201 ms |
コンパイル使用メモリ | 86,120 KB |
最終ジャッジ日時 | 2025-01-05 10:02:42 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include<algorithm> #include<map> #include<iostream> #include<vector> using namespace std; typedef long long lint; typedef vector<int>vi; typedef pair<int,int>pii; #define rep(i,n)for(int i=0;i<(int)(n);++i) int main(){ string s; cin>>s; int n=s.length(); vi acc(n+1); rep(i,n){ acc[i+1]=acc[i]+(s[i]=='A'?1:-1); } int ma=0; map<int,vi> tt; rep(i,n+1){ tt[acc[i]].push_back(i); } for(auto &e:tt){ vi &v=e.second; ma=max(ma,v[v.size()-1]-v[0]); } cout<<ma<<endl; }