結果

問題 No.2240 WAC
ユーザー kuro_Bkuro_B
提出日時 2023-05-11 19:34:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 956 ms / 2,000 ms
コード長 1,928 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 23,704 KB
最終ジャッジ日時 2023-08-18 11:30:11
合計ジャッジ時間 12,087 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
10,448 KB
testcase_01 AC 35 ms
10,604 KB
testcase_02 AC 35 ms
10,556 KB
testcase_03 AC 35 ms
10,444 KB
testcase_04 AC 35 ms
10,452 KB
testcase_05 AC 35 ms
10,520 KB
testcase_06 AC 36 ms
10,604 KB
testcase_07 AC 35 ms
10,452 KB
testcase_08 AC 36 ms
10,608 KB
testcase_09 AC 35 ms
10,628 KB
testcase_10 AC 956 ms
23,704 KB
testcase_11 AC 951 ms
21,064 KB
testcase_12 AC 140 ms
11,368 KB
testcase_13 AC 36 ms
10,692 KB
testcase_14 AC 36 ms
10,520 KB
testcase_15 AC 36 ms
11,116 KB
testcase_16 AC 875 ms
20,732 KB
testcase_17 AC 36 ms
10,868 KB
testcase_18 AC 117 ms
11,812 KB
testcase_19 AC 287 ms
14,952 KB
testcase_20 AC 36 ms
11,184 KB
testcase_21 AC 134 ms
11,592 KB
testcase_22 AC 668 ms
20,364 KB
testcase_23 AC 340 ms
15,420 KB
testcase_24 AC 391 ms
15,488 KB
testcase_25 AC 413 ms
15,600 KB
testcase_26 AC 35 ms
10,732 KB
testcase_27 AC 35 ms
10,732 KB
testcase_28 AC 210 ms
14,764 KB
testcase_29 AC 88 ms
11,984 KB
testcase_30 AC 36 ms
11,020 KB
testcase_31 AC 36 ms
11,080 KB
testcase_32 AC 89 ms
11,588 KB
testcase_33 AC 36 ms
10,996 KB
testcase_34 AC 37 ms
10,968 KB
testcase_35 AC 35 ms
10,736 KB
testcase_36 AC 408 ms
15,468 KB
testcase_37 AC 36 ms
10,968 KB
testcase_38 AC 114 ms
11,568 KB
testcase_39 AC 910 ms
21,068 KB
testcase_40 AC 36 ms
10,956 KB
testcase_41 AC 852 ms
20,984 KB
testcase_42 AC 811 ms
20,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

###スニペット始まり###
import sys, re
from copy import copy, deepcopy
from math import ceil, floor, sqrt,factorial, gcd, pi, degrees, radians, sin, asin, cos, acos, tan, atan2
from statistics import mean, median
from collections import Counter, deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations, accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce, lru_cache
from string import ascii_uppercase, ascii_lowercase
from decimal import Decimal, ROUND_HALF_UP #四捨五入用

def input(): return sys.stdin.readline().rstrip('\n')
#easy-testのpypyでは再帰数を下げる。
if __file__=='prog.py':
    sys.setrecursionlimit(10**5)
else:
    sys.setrecursionlimit(10**6)

def lcm(a, b): return a * b // gcd(a, b)

#3つ以上の最大公約数/最小公倍数。Nを要素数、Mを数値の大きさとして、O(NlogM)
def gcd_v2(l: list): return reduce(gcd, l)
def lcm_v2(l: list): return reduce(lcm, l)

#nPk
def nPk(n, k): return factorial(n) // factorial(n - k)

#逆元
def modinv(a, mod=10**9+7): return pow(a, mod-2, mod)
INF = float('inf')
MOD = 10 ** 9 + 7
###スニペット終わり###

N, M=map(int, input().split())
L=2*N+2*M
S=input()

A_idx=deque()
for i in range(L):
    if S[L-1-i]=='A':
        A_idx.append(L-1-i)
    elif S[L-1-i]=='W':
        if not A_idx:
            print('No')
            exit()
        else:
            A_idx.popleft()

A_idx=set(A_idx)
res=''

for i,s in enumerate(S):
    if s=='A' and i in A_idx:
        res+=s
    elif s=='C':
        res+=s

#あとは尺取り

q = deque()
A_cnt=0
C_cnt=0
for c in res:
    q.append(c) 
    if c=='A':
        A_cnt+=1
    else:
        C_cnt+=1
    
    if A_cnt<C_cnt:
        print('No')
        exit()
    else:
        if c=='C':
            A_cnt-=1
            C_cnt-=1
print('Yes')
0