結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
gurualo
|
| 提出日時 | 2018-04-16 10:37:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,049 bytes |
| コンパイル時間 | 998 ms |
| コンパイル使用メモリ | 108,316 KB |
| 実行使用メモリ | 27,648 KB |
| 最終ジャッジ日時 | 2024-06-27 20:16:49 |
| 合計ジャッジ時間 | 2,023 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 6 |
ソースコード
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <complex>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(t,c) for(typeof((c).begin()) t=(c).begin(); t!=(c).end(); ++t)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(t,a,b) for(int t=(a);t<(b);++t)
#define REP(t,n) FOR(t,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x) cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;
const LL mod = 1000000007;
LL gcd(LL a, LL b) { if (a%b == 0) { return b; } else return gcd(b, a%b); }
LL lcm(LL a, LL b) { return a / gcd(a, b)*b; }
#define Yes_ cout<<"Yes"<<endl; return 0;
#define No_ cout<<"No"<<endl; return 0;
#define YES_ cout<<"YES"<<endl; return 0;
#define NO_ cout<<"NO"<<endl; return 0;
#define POSSIBLE cout<<"POSSIBLE"<<endl; return 0;
#define IMPOSSIBLE cout<<"IMPOSSIBLE"<<endl; return 0;
struct D {
int diff;
int index;
};
int main() {
string s;
cin >> s;
int n = SZ(s);
VI numA(n); VI numB(n),diff(n);
int maxdiff;
map<int,vector<int> > dpair;
REP(i, SZ(s)) {
if (i > 0) {
numA[i] = numA[i - 1];
numB[i] = numB[i - 1];
}
if (s[i] == 'A') {
numA[i]++;
}
else {
numB[i]++;
}
diff[i] = numA[i] - numB[i];
//D d{ diff[i],i };
//dpair[diff[i]].push_back(d);
dpair[diff[i]].push_back(i);
}
int m = 0;
//for (auto a : dpair) {
for (map<int , VI>::iterator a = dpair.begin(); a != dpair.end(); a++){
if (a->first == 0) {
int l = a->second[a->second.size() - 1];
m = max(m, l);
}
if (a->second.size() >= 2) {
int l = a->second[a->second.size() - 1] - a->second[0];
m = max(m, l);
}
}
cout << m << endl;
}
gurualo