結果
問題 |
No.672 最長AB列
|
ユーザー |
![]() |
提出日時 | 2018-04-13 23:13:24 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,400 bytes |
コンパイル時間 | 917 ms |
コンパイル使用メモリ | 141,568 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-30 12:16:26 |
合計ジャッジ時間 | 1,688 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 WA * 9 |
ソースコード
#include <iostream> #include <fstream> #include <string> #include <cstring> #include <cmath> #include <cstdlib> #include <ctime> #include <vector> #include <algorithm> #include <numeric> #include <map> #include <set> #include <stack> #include <queue> #include <deque> #include <functional> #include <cctype> #include <list> //#include <boost/multiprecision/cpp_int.hpp> #define BIT(a) (1 << (a)) using namespace std; //using namespace boost::multiprecision; long long MOD = 1000000007; long long mod_pow(long long x, long long n){ long long res = 1; for(int i = 0;i < 60; i++){ if(n >> i & 1) res = res * x % MOD; x = x * x % MOD; } return res; } char s[200005]; int main(void){ cin >> s; int len = strlen(s); int Acnt = 0; int Amax = 0; int Bcnt = 0; int Bmax = 0; int ans = 0; for (int i = 0; i < len; i++){ if (s[i] == 'A'){ Acnt++; Amax = Amax<Acnt?Acnt:Amax; } if (s[i] == 'B'){ if (Acnt > 0) --Acnt; ans = ans<Amax-Acnt?Amax-Acnt:ans; } } for (int i = 0; i < len; i++){ if (s[i] == 'B'){ Bcnt++; Bmax = Bmax<Bcnt?Bcnt:Bmax; } if (s[i] == 'A'){ if (Bcnt > 0) --Bcnt; ans = ans<Bmax-Bcnt?Bmax-Bcnt:ans; } } cout << ans*2 << endl; return 0; }