結果

問題 No.2240 WAC
ユーザー navel_tosnavel_tos
提出日時 2023-03-10 21:57:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 1,434 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 11,960 KB
実行使用メモリ 13,588 KB
最終ジャッジ日時 2023-10-18 07:44:11
合計ジャッジ時間 8,573 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,108 KB
testcase_01 AC 30 ms
10,108 KB
testcase_02 AC 30 ms
10,108 KB
testcase_03 AC 29 ms
10,108 KB
testcase_04 AC 30 ms
10,108 KB
testcase_05 AC 29 ms
10,108 KB
testcase_06 AC 29 ms
10,108 KB
testcase_07 AC 29 ms
10,108 KB
testcase_08 AC 29 ms
10,108 KB
testcase_09 AC 29 ms
10,108 KB
testcase_10 AC 316 ms
13,588 KB
testcase_11 AC 313 ms
13,588 KB
testcase_12 AC 319 ms
13,588 KB
testcase_13 AC 131 ms
11,404 KB
testcase_14 AC 74 ms
10,672 KB
testcase_15 AC 231 ms
12,316 KB
testcase_16 AC 283 ms
13,076 KB
testcase_17 AC 190 ms
12,004 KB
testcase_18 AC 90 ms
10,924 KB
testcase_19 AC 106 ms
11,080 KB
testcase_20 AC 246 ms
12,612 KB
testcase_21 AC 143 ms
11,460 KB
testcase_22 AC 166 ms
11,768 KB
testcase_23 AC 136 ms
11,404 KB
testcase_24 AC 222 ms
12,456 KB
testcase_25 AC 222 ms
12,192 KB
testcase_26 AC 105 ms
11,092 KB
testcase_27 AC 85 ms
10,816 KB
testcase_28 AC 119 ms
11,124 KB
testcase_29 AC 62 ms
10,516 KB
testcase_30 AC 165 ms
11,704 KB
testcase_31 AC 289 ms
13,196 KB
testcase_32 AC 82 ms
10,696 KB
testcase_33 AC 180 ms
11,756 KB
testcase_34 AC 207 ms
12,300 KB
testcase_35 AC 55 ms
10,424 KB
testcase_36 AC 223 ms
12,316 KB
testcase_37 AC 262 ms
12,720 KB
testcase_38 AC 126 ms
11,184 KB
testcase_39 AC 298 ms
13,204 KB
testcase_40 AC 163 ms
11,708 KB
testcase_41 AC 218 ms
12,424 KB
testcase_42 AC 212 ms
12,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yukicoder380B

'''
Aで3WA。先が思いやられる。

N個の(W,A), M個の(A,C)を与える。
①順番を変えないように2文字選んで
②取り除く
をくり返すことで、N個のWAとM個のACを作れるか判定せよ。

W-A のマッチングを前から貪欲に行った後、A-Cのマッチングを後ろから貪欲に行えばよい。
matched[i]: i番目のAは使用済 として管理すればいいか。

違うな。
W-A のマッチングで使うAは右端から使いたくて、
A-C のマッチングで使うAは左端から使いたいのか。
matched[i]: TrueならA-Cのマッチング用のA, FalseならW-Aのマッチング用のA
'''
N,M=list(map(int,input().split()))
S=input()
matched=[False]*((N+M)*2)

Acount=M
for i in range((N+M)*2):
    if S[i]=='A' and Acount>0:
        matched[i]=True
        Acount-=1

hantei=True
Wcount=0
for i in range((N+M)*2):
    if S[i]=='W':
        Wcount+=1
    elif S[i]=='A':
        if matched[i]==False:
            if Wcount>0:
                Wcount-=1
            else:
                hantei=False

Ccount=0
for i in range((N+M)*2-1,-1,-1):
    if S[i]=='C':
        Ccount+=1
    elif S[i]=='A':
        if matched[i]==True:
            if Ccount>0:
                Ccount-=1
            else:
                hantei=False

print('Yes') if hantei else print('No')
                
0