結果

問題 No.672 最長AB列
ユーザー CleyLCleyL
提出日時 2020-03-07 20:30:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 865 bytes
コンパイル時間 824 ms
コンパイル使用メモリ 76,404 KB
実行使用メモリ 6,936 KB
最終ジャッジ日時 2024-04-23 14:19:04
合計ジャッジ時間 4,004 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 19 ms
6,804 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
  
}
0