結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2018-07-26 13:35:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 133 ms / 2,000 ms |
| コード長 | 504 bytes |
| コンパイル時間 | 1,773 ms |
| コンパイル使用メモリ | 176,576 KB |
| 実行使用メモリ | 16,128 KB |
| 最終ジャッジ日時 | 2024-07-01 03:17:13 |
| 合計ジャッジ時間 | 3,148 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//INSERT ABOVE HERE
signed main(){
string s;
cin>>s;
Int n=s.size();
Int ans=0;
map<Int, Int> m;
m[0]=-1;
Int k=0;
for(Int i=0;i<n;i++){
if(s[i]=='A') k++;
else k--;
if(!m.count(k)) m[k]=i;
chmax(ans,i-m[k]);
}
cout<<ans<<endl;
return 0;
}
beet