結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2021-03-18 23:31:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 2,000 ms |
| コード長 | 701 bytes |
| コンパイル時間 | 1,956 ms |
| コンパイル使用メモリ | 174,724 KB |
| 実行使用メモリ | 13,568 KB |
| 最終ジャッジ日時 | 2024-11-17 05:51:15 |
| 合計ジャッジ時間 | 3,060 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include<bits/stdc++.h>
template<class T> inline bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
using namespace std;
using ll = long long;
int main(){
string s; cin >> s;
vector<int> cnt(s.size()+1, 0);
for (int i=0;i<s.size();++i){
if (s[i]=='A') cnt[i+1]=cnt[i]+1;
else cnt[i+1]=cnt[i]-1;
}
int ans = 0;
map<int,int> mp;
for (int i=0; i<s.size()+1; ++i) {
if (mp.find(cnt[i]) != mp.end()) {
chmax(ans, i-mp[cnt[i]]);
}
else {
mp[cnt[i]]=i;
}
}
cout << ans << endl;
}
tktk_snsn