結果

問題 No.672 最長AB列
ユーザー Naco
提出日時 2019-10-21 16:48:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 571 bytes
コンパイル時間 1,509 ms
コンパイル使用メモリ 166,768 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-02 17:45:25
合計ジャッジ時間 2,367 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
    string s; cin >> s;
    int cnta=0,cntb=0;
    int N=s.size();
    for(int i=0;i<N;i++){
        if(s[i]=='A') cnta++;
        else cntb++;
    }
    for(int i=0;i<N;i++){
        if(cnta==cntb){
            cout << cnta+cntb << endl;
            return 0;
        }

        if(s[i]=='A'&&s[N-1-i]=='A'){
            cnta--;
        }else if(s[i]=='B'&&s[N-1-i]=='B'){
            cntb--;
        }else{
            if(cnta>cntb) cnta--;
            else cntb--;
        }
    }
    cout << 0 << endl;
    
}
0