QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#605535 | #2513. A Color Game | ucup-team3474 | WA | 28ms | 7876kb | C++20 | 1.3kb | 2024-10-02 17:46:52 | 2024-10-02 17:46:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1919810;
typedef long long ll;
typedef pair<ll,ll> PII;
ll n,m,k;
ll a[N],b[N];
char s[N];
bool dp[514][514];
bool check(int l,int r){
for(int i=l;i<r;i++){
if(dp[l][i]&&dp[i+1][r]) return true;
}
int len=r-l+1;
int lastl,lastr;
for(int c=1;c<=7;c++){
int cnt=0;
int i=l,j=i;
bool flag=1;
while(i<=r){
if(a[i]==c){
cnt++;
i++;
continue;
}
j=i;
while(j<=r&&a[j]!=c) j++;
flag&=dp[i][j-1];
i=j;
}
if(flag&&cnt>=m) return true;
}
return false;
}
int main(){
scanf("%s",s+1);
cin>>m;
n=strlen(s+1);
for(int i=1;i<=n;i++){
if(s[i]=='R') a[i]=1;
else if(s[i]=='G') a[i]=2;
else if(s[i]=='B') a[i]=3;
else if(s[i]=='C') a[i]=4;
else if(s[i]=='M') a[i]=5;
else if(s[i]=='Y') a[i]=6;
else a[i]=7;
}
for(int len=1;len<=n;len++){
for(int i=1;i+len-1<=n;i++){
int l=i,r=i+len-1;
dp[l][r]=check(l,r);
// cout<<l<<" "<<r<<" "<<dp[l][r]<<endl;
}
}
if(dp[1][n]) puts("Yes");
else puts("No");
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5816kb
input:
BBBRRRRRRGGGB 3
output:
Yes
result:
ok single line: 'Yes'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5632kb
input:
BBBRRRRRRGGGB 4
output:
No
result:
ok single line: 'No'
Test #3:
score: 0
Accepted
time: 1ms
memory: 5868kb
input:
RRRRGGGRRRRRG 3
output:
Yes
result:
ok single line: 'Yes'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5972kb
input:
GMYCGMRMGYMRMKCBKBMKKBMMKBBKMBMRRMGYKKMBKMYRGGBMRMKKKBRCMKYCCKYGYYKKCKRCYGGKGRBCKMYMRCRGBRRYCCKKRRKRCKMMMGCCGYYKMCRGMKCYBMRRKYYRRKGGRBMCKGBBYYGGGBBYBBRCCMGKKGRGRMRRBRCYGGGKBRKCBYCKMMBRCGKCCYYMMCKGRBYRRGBBCGYKBBMKRBBKGCRBYCKMYKMCKMBRMGGYBKBRBMYGGCKYCMYKBRCCGCYRRRKCKCBKCMCYBKRBKMCCYRBKBGGMGMCBGMBMYCCK 1
output:
Yes
result:
ok single line: 'Yes'
Test #5:
score: -100
Wrong Answer
time: 28ms
memory: 7876kb
input:
KKCCCCCKYYYYYYKKKCRRCCBBBGGMMGCKKBBBBBRCCRRCRRYYCCYYBGGGBKKKBKKKCMKKMCCCGGGCCCCBBBCCKMMMKCCYYBBCCCCCCCCCYYCCCCBMMBRRRBBGGMKKBYMMMYYBBBBYYYYKCCCMMCKKMMMKKGGMBBRRBBBBKKBBBMMMMKKMMMKKKMMYYGMYYYMRRBMMMBGRRGGMMCCGRRBBBGCGGGCBBBCCBGGGGCRKKBBBRRYYYBBBYYKKKYYYBBYYBBBBCCCRKYGGGYYKKKKKKKKKRCCCYKKRRRKKMMMKMMC 2
output:
No
result:
wrong answer 1st lines differ - expected: 'Yes', found: 'No'