結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
zaki_joho
|
| 提出日時 | 2018-12-24 15:11:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 82 ms / 2,000 ms |
| コード長 | 734 bytes |
| コンパイル時間 | 1,547 ms |
| コンパイル使用メモリ | 166,560 KB |
| 実行使用メモリ | 12,672 KB |
| 最終ジャッジ日時 | 2024-09-25 11:01:29 |
| 合計ジャッジ時間 | 2,712 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int res = 0;
string s;
cin >> s;
int n = s.length();
map<int, int> mp;
mp[0] = 0;
int a = 0, b = 0;
for (int i = 0; i < n; i++)
{
if (s[i] == 'A')
a++;
else
b++;
if (mp.find(a - b) != mp.end())
{
res = max(res, a + b - mp[a - b]);
}
else
{
mp[a - b] = a + b;
}
}
cout << res << endl;
}
zaki_joho