結果

問題 No.2240 WAC
ユーザー srjywrdnprkt
提出日時 2023-04-22 06:05:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,196 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 107,032 KB
最終ジャッジ日時 2025-02-12 12:56:41
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

int main(){

    int N, M, l, K, cnt=0;
    string S;
    cin >> N >> M >> S;
    K = (N+M)*2;
    string T="", U="";

    for (int i=0; i<K; i++){
        if (S[i] == 'A' && cnt < M){
            T += '(';
            cnt++;
        }
        else if (S[i] == 'C') T += ')';
    }

    reverse(S.begin(), S.end());
    cnt = 0;
    for (int i=0; i<K; i++){
        if (S[i] == 'A' && cnt < N){
            U += ')';
            cnt++;
        }
        else if (S[i] == 'W') U += '(';
    }
    reverse(U.begin(), U.end());

    l = 0;
    for (int i=0; i<M*2; i++){
        if (T[i] == '(') l++;
        else l--;
        if (l < 0){
            cout << "No" << endl;
            return 0;
        }
    }
    l = 0;
    for (int i=0; i<N*2; i++){
        if (U[i] == '(') l++;
        else l--;
        if (l < 0){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}
0