結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
oxyshower
|
| 提出日時 | 2020-01-11 19:37:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 85 ms / 2,000 ms |
| コード長 | 517 bytes |
| コンパイル時間 | 1,661 ms |
| コンパイル使用メモリ | 175,488 KB |
| 実行使用メモリ | 17,408 KB |
| 最終ジャッジ日時 | 2024-11-25 08:43:43 |
| 合計ジャッジ時間 | 2,528 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
#define int long long
signed main(){
string s; cin >> s;
int n = s.size();
vector<int> dp(n+1, 0);
map<int, int> mp;
for(int i = 0; i < n; i++){
if(s[i] == 'A') dp[i+1] = dp[i] + 1;
if(s[i] == 'B') dp[i+1] = dp[i] - 1;
mp[dp[i+1]] = i;
}
int ans = 0;
for(int i = 0; i <= n; i++){
ans = max(ans, mp[dp[i]] - i + 1);
}
if(ans == 1) ans = 0;
cout << ans << endl;
return 0;
}
oxyshower