QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#728576 | #2513. A Color Game | vwxyz# | WA | 2600ms | 11188kb | Python3 | 1.6kb | 2024-11-09 15:28:29 | 2024-11-09 15:28:30 |
Judging History
answer
def Run_Length(lst):
run_length=[]
if lst:
prev=lst[0]
cnt=1
for x in lst[1:]:
if x==prev:
cnt+=1
else:
run_length.append((prev,cnt))
prev=x
cnt=1
run_length.append((prev,cnt))
return run_length
S,M=input().split()
N=len(S)
S=list(S)
for i in range(N):
S[i]=ord(S[i])-65
M=int(M)
dp=[[0]*(N+1) for n in range(N+1)]
prev=[[None]*N for a in range(26)]
for a in range(26):
for i in range(N):
if S[i]==a:
prev[a][i]=i
elif i:
prev[a][i]=prev[a][i-1]
nxt=[[None]*N for a in range(26)]
for a in range(26):
for i in range(N-1,-1,-1):
if S[i]==a:
nxt[a][i]=i
elif i<N-1:
nxt[a][i]=nxt[a][i+1]
for d in range(N+1):
for l in range(N-d+1):
r=l+d
if d==0:
dp[l][r]=1
else:
for m in range(l+1,r):
dp[l][r]|=dp[l][m]&dp[m][r]
for s in range(26):
idx=[]
i=nxt[s][l]
while i!=None and i<r:
idx.append(i)
if i==N-1:
break
i=nxt[s][i+1]
L,R=[l],[]
for i in idx:
R.append(i)
L.append(i+1)
R.append(r)
if all(dp[ll][rr] for ll,rr in zip(L,R)) and len(idx)>=M:
dp[l][r]=1
if dp[0][N]:
ans="Yes"
else:
ans="No"
print(ans)
详细
Test #1:
score: 100
Accepted
time: 16ms
memory: 10588kb
input:
BBBRRRRRRGGGB 3
output:
Yes
result:
ok single line: 'Yes'
Test #2:
score: 0
Accepted
time: 8ms
memory: 10532kb
input:
BBBRRRRRRGGGB 4
output:
No
result:
ok single line: 'No'
Test #3:
score: 0
Accepted
time: 16ms
memory: 10656kb
input:
RRRRGGGRRRRRG 3
output:
Yes
result:
ok single line: 'Yes'
Test #4:
score: 0
Accepted
time: 2600ms
memory: 11072kb
input:
GMYCGMRMGYMRMKCBKBMKKBMMKBBKMBMRRMGYKKMBKMYRGGBMRMKKKBRCMKYCCKYGYYKKCKRCYGGKGRBCKMYMRCRGBRRYCCKKRRKRCKMMMGCCGYYKMCRGMKCYBMRRKYYRRKGGRBMCKGBBYYGGGBBYBBRCCMGKKGRGRMRRBRCYGGGKBRKCBYCKMMBRCGKCCYYMMCKGRBYRRGBBCGYKBBMKRBBKGCRBYCKMYKMCKMBRMGGYBKBRBMYGGCKYCMYKBRCCGCYRRRKCKCBKCMCYBKRBKMCCYRBKBGGMGMCBGMBMYCCK 1
output:
Yes
result:
ok single line: 'Yes'
Test #5:
score: -100
Wrong Answer
time: 2280ms
memory: 11188kb
input:
KKCCCCCKYYYYYYKKKCRRCCBBBGGMMGCKKBBBBBRCCRRCRRYYCCYYBGGGBKKKBKKKCMKKMCCCGGGCCCCBBBCCKMMMKCCYYBBCCCCCCCCCYYCCCCBMMBRRRBBGGMKKBYMMMYYBBBBYYYYKCCCMMCKKMMMKKGGMBBRRBBBBKKBBBMMMMKKMMMKKKMMYYGMYYYMRRBMMMBGRRGGMMCCGRRBBBGCGGGCBBBCCBGGGGCRKKBBBRRYYYBBBYYKKKYYYBBYYBBBBCCCRKYGGGYYKKKKKKKKKRCCCYKKRRRKKMMMKMMC 2
output:
No
result:
wrong answer 1st lines differ - expected: 'Yes', found: 'No'