結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
pin
|
| 提出日時 | 2018-04-16 22:24:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 151 ms / 2,000 ms |
| コード長 | 900 bytes |
| コンパイル時間 | 1,021 ms |
| コンパイル使用メモリ | 95,312 KB |
| 実行使用メモリ | 22,144 KB |
| 最終ジャッジ日時 | 2024-06-27 20:17:50 |
| 合計ジャッジ時間 | 2,280 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int dx[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
int dy[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
const ll MOD = 1000000007;
const ll INF = 1000000000;
const int MAX = 10000000;
int main() {
string s;
cin >> s;
map<int, int> pos;
map<int, bool> exist;
int count = 0;
exist[count] = true;
pos[count] = -1;
int ans = 0;
for (int i = 0; i < s.size(); i++){
if (s[i] == 'A') count++;
else count--;
if (exist[count]){
ans = max(ans, i - pos[count]);
}
else{
pos[count] = i;
exist[count] = true;
}
}
cout << ans << endl;
}
pin