結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-13 22:37:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 446 bytes |
| コンパイル時間 | 752 ms |
| コンパイル使用メモリ | 79,428 KB |
| 最終ジャッジ日時 | 2025-01-05 10:03:55 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 6 |
ソースコード
#include <iostream>
#include <map>
using namespace std;
int main()
{
map<int, int> left;
string s;
cin >> s;
int ans = 0;
int maxi = 0;
left[0] = 0;
for (int i = 0; i < s.size(); i++) {
ans += (s[i] == 'A' ? 1 : -1);
if (left.find(ans) == left.end()) {
left[ans] = i;
} else {
maxi = max(maxi, i - left[ans]);
}
}
cout << maxi << endl;
return 0;
}