結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
DaYuanChi
|
| 提出日時 | 2021-01-27 00:57:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 558 bytes |
| コンパイル時間 | 1,957 ms |
| コンパイル使用メモリ | 174,412 KB |
| 実行使用メモリ | 15,232 KB |
| 最終ジャッジ日時 | 2024-06-23 22:48:12 |
| 合計ジャッジ時間 | 2,980 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int a[200005];
int b[200005];
int c[200005];
map<int,int> mp;
int main(){
string s;
cin >> s;
int n = s.size();
for(int i = 1; i <= n; i++){
if(s[i-1]=='A'){
a[i] = a[i-1]+1;
b[i] = b[i-1];
}else{
a[i] = a[i-1];
b[i] = b[i-1]+1;
}
}
int ans = 0;
for(int i = 1; i <= n; i++) c[i] = a[i]-b[i];
for(int i = 1; i <= n; i++){
if(mp[c[i]]==0) mp[c[i]] = i;
else ans = max(ans, i-mp[c[i]]);
}
cout << ans << endl;
return 0;
}
DaYuanChi