結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
incuiio
|
| 提出日時 | 2023-05-10 15:40:15 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 144 ms / 2,000 ms |
| コード長 | 1,081 bytes |
| コンパイル時間 | 1,316 ms |
| コンパイル使用メモリ | 134,140 KB |
| 最終ジャッジ日時 | 2025-02-12 21:11:29 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>
#include <cassert>
#include <regex>
using std::cout;
using std::cin;
using std::string;
using std::vector;
struct pos
{
int first, last;
pos()
{
first = last = -1;
}
};
int main()
{
string s;
cin >> s;
std::map<int, pos> arr;
arr[0].first = 0;
arr[0].last = 0;
int sum = 0;
for (int i = 0; i < s.size(); i++)
{
if (s[i] == 'A')
{
sum++;
}
else
{
sum--;
}
if (arr[sum].first == -1)
{
arr[sum].first = i+1;
}
arr[sum].last = i+1;
}
int max = 0;
for (const auto [k, p] : arr)
{
if (p.first == -1)
{
continue;
}
max = std::max(max, p.last - p.first);
}
cout << max;
}
incuiio