結果

問題 No.2240 WAC
ユーザー yuyu_5510yuyu_5510
提出日時 2023-03-10 21:57:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 877 bytes
コンパイル時間 1,511 ms
コンパイル使用メモリ 169,192 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-18 04:13:46
合計ジャッジ時間 3,127 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    ll sn= (int)s.size();
    bool ok = true;
    vector<bool> used(sn+1);
    ll wcnt = 0;
    int acnt = 0;

    for(int i = sn-1;i >= 0;--i){
        if(s[i] == 'W') ++wcnt;
        if(s[i] == 'A') ++acnt;
        if(acnt < wcnt){
            ok = false;
        }
    }

    for(int i = sn-1;i >= 0;--i){
        if(s[i] == 'A'){
            used[i] = true;
            --wcnt;
            if(wcnt == 0) break;
        }
    }

    acnt = 0;
    int ccnt = 0;
    for(int i = 0;i < sn;++i){
        if(s[i] == 'A' && !used[i]) ++acnt;
        if(s[i] == 'C') ++ccnt;

        if(acnt < ccnt){
            ok = false;
        } 
    }

    if(ok){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}
0