結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2020-03-07 20:30:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 865 bytes |
| コンパイル時間 | 1,398 ms |
| コンパイル使用メモリ | 76,124 KB |
| 実行使用メモリ | 6,804 KB |
| 最終ジャッジ日時 | 2024-10-15 14:28:25 |
| 合計ジャッジ時間 | 4,593 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 2 WA * 14 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct dta{
int n;
int A,B;
};
bool cmp(const dta &a,dta &b){
if(a.A==b.A){
if(a.B==b.B){
return a.n < b.n;
}
return a.B < b.B;
}
return a.A < b.A;
}
int nwa,nwb;
int main(){
string s;cin>>s;
vector<dta> A;
A.push_back({-1,0,0});
for(int i = 0; s.size() > i; i++){
if(s[i] == 'A')nwa++;
else nwb++;
if(nwa*nwb){
nwa--;
nwb--;
}
A.push_back({i,nwa,nwb});
}
sort(A.begin(),A.end(),cmp);
int nA = A[0].A;
int nB = A[0].B;
int nN = A[0].n;
int ans = 0;
for(int i = 1; A.size() > i; i++){
if(nA == A[i].A && nB == A[i].B){
cout << A[i].n << " " << nN << endl;
ans = max(ans,A[i].n-nN);
}else{
nA = A[i].A;
nB = A[i].B;
nN = A[i].n;
}
}
cout << ans << endl;
}