結果
問題 | No.672 最長AB列 |
ユーザー | moti |
提出日時 | 2020-04-29 13:54:11 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,838 bytes |
コンパイル時間 | 2,031 ms |
コンパイル使用メモリ | 168,912 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-05-06 04:31:23 |
合計ジャッジ時間 | 2,727 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 11 ms
5,376 KB |
testcase_10 | AC | 13 ms
5,376 KB |
testcase_11 | AC | 15 ms
5,376 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 10 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) #define watch(a) { std::cout << #a << " = " << a << "\n"; } template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); } template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); } template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; } template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; } template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; } typedef long long ll; int const inf = INT_MAX / 2; int main() { string S; cin >> S; int const N = S.size(); vector<int> A(N + 1), B(N + 1); int max_len = 0; rep(i, N) { A[i + 1] += A[i] + (S[i] == 'A'); B[i + 1] += B[i] + (S[i] == 'B'); auto diff = A[i + 1] - B[i + 1]; if (diff >= 0) { auto iter = lower_bound(A.begin(), A.begin() + i + 1, diff); if (iter != A.end() && *iter == diff) { max_len = max(max_len, (int)(A.begin() + i + 1 - iter)); } } else { diff *= -1; auto iter = lower_bound(B.begin(), B.begin() + i + 1, diff); if (iter != B.end() && *iter == diff) { // cout << "p: " << (iter - B.begin()) << ", diff: " << diff // << ", len: " << (int)(B.begin() + i + 1 - iter) << "\n"; max_len = max(max_len, (int)(B.begin() + i + 1 - iter)); } } } // rep(i, N + 1) cout << A[i] << " "; cout << "\n"; // rep(i, N + 1) cout << B[i] << " "; cout << "\n"; cout << max_len << "\n"; }