結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
kyo1
|
| 提出日時 | 2021-01-04 15:16:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 421 bytes |
| コンパイル時間 | 1,680 ms |
| コンパイル使用メモリ | 198,388 KB |
| 最終ジャッジ日時 | 2025-01-17 09:35:08 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string S;
cin >> S;
const int N = S.size();
int cur = 0, res = 0;
map<int, int> mp;
for (int i = 0; i < N; i++) {
cur += S[i] == 'A' ? 1 : -1;
if (mp.find(cur) == mp.end()) {
mp[cur] = i;
} else {
res = max(res, i - mp[cur]);
}
}
cout << res << '\n';
return 0;
}
kyo1