結果
問題 | No.672 最長AB列 |
ユーザー | pin |
提出日時 | 2018-04-16 22:24:25 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 149 ms / 2,000 ms |
コード長 | 900 bytes |
コンパイル時間 | 1,986 ms |
コンパイル使用メモリ | 93,692 KB |
実行使用メモリ | 22,060 KB |
最終ジャッジ日時 | 2023-09-10 04:35:58 |
合計ジャッジ時間 | 2,555 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 149 ms
22,060 KB |
testcase_10 | AC | 101 ms
12,744 KB |
testcase_11 | AC | 96 ms
12,684 KB |
testcase_12 | AC | 14 ms
4,376 KB |
testcase_13 | AC | 14 ms
4,380 KB |
testcase_14 | AC | 14 ms
4,376 KB |
testcase_15 | AC | 14 ms
4,376 KB |
testcase_16 | AC | 14 ms
4,376 KB |
testcase_17 | AC | 95 ms
12,780 KB |
testcase_18 | AC | 7 ms
4,380 KB |
ソースコード
#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; }