結果

問題 No.672 最長AB列
ユーザー NacoNaco
提出日時 2019-10-21 16:48:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 571 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 164,972 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 15:01:34
合計ジャッジ時間 2,418 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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