結果
問題 | No.672 最長AB列 |
ユーザー |
![]() |
提出日時 | 2019-11-14 23:36:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 454 bytes |
コンパイル時間 | 1,637 ms |
コンパイル使用メモリ | 176,424 KB |
実行使用メモリ | 12,908 KB |
最終ジャッジ日時 | 2024-09-22 05:29:11 |
合計ジャッジ時間 | 2,845 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 6 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair<int,int> P; int main(){ string s; cin >> s; int n = sz(s); map<int,int> mp; mp[0] = 1; int res = 0; int cnt = 0; rep(i,n) { if (s[i] == 'A') cnt++; else cnt--; if (mp.count(cnt)) res = max(res, i - mp[cnt]); else mp[cnt] = i; } cout << res << endl; return 0; }