QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#491485 | #8776. Not Another Constructive! | do_it_tomorrow | WA | 2ms | 28200kb | C++14 | 1.3kb | 2024-07-25 19:50:43 | 2024-07-25 19:50:43 |
Judging History
answer
#include<iostream>
#include<bitset>
using namespace std;
const int N=55;
int n,k;
char s[N],ans[N];
bitset<3005>f[N][N][N];
void print(int i,int a,int b,int sum){
if(i==0) return;
if(s[i]!='N'&&s[i]!='A'&&s[i]!='C'&&f[i-1][a][b][sum]){
if(s[i]=='?')ans[i]='B';
else ans[i]=s[i];
print(i-1,a,b,sum);
}
else if(a-1>=0&&(s[i]=='N'||s[i]=='?')&&f[i-1][a-1][b][sum]){
ans[i]='N';
print(i-1,a-1,b,sum);
}
else if(sum-a*b>=0&&(s[i]=='A'||s[i]=='?')&&f[i-1][a][b][sum-a*b]){
ans[i]='A';
print(i-1,a,b,sum-a*b);
}
else if((s[i]=='C'||s[i]=='?')&&f[i-1][a][b+1][sum]){
ans[i]='C';
print(i-1,a,b+1,sum);
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>k>>s+1;
for(int i=1;i<=n;i++) f[0][0][i][0]=1;
for(int i=1;i<=n;i++){
for(int a=0;a<=i;a++){
for(int b=0;b<=n-i;b++){
if(s[i]=='?'||s[i]=='N') f[i][a+1][b]|=f[i-1][a][b];
if(s[i]=='?'||s[i]=='A') f[i][a][b]|=(f[i-1][a][b]<<(a*b));
if(s[i]=='?'||s[i]=='C') f[i][a][b]|=f[i-1][a][b+1];
if(s[i]!='N'&&s[i]!='A'&&s[i]!='C') f[i][a][b]|=f[i-1][a][b];
}
}
}
for(int i=0;i<=n;i++){
if(f[n][i][0][k]){
print(n,i,0,k);
for(int j=1;j<=n;j++) cout<<ans[j];
return 0;
}
}
cout<<-1<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 28200kb
input:
22 2 N??A??????C???????????
output:
NABABBBBBBCBBBBBBBBBBB
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 24128kb
input:
18 0 COUNTINGSATELLITES
output:
COUNTINGSATELLITES
result:
ok correct
Test #3:
score: 0
Accepted
time: 1ms
memory: 7644kb
input:
2 1 ??
output:
-1
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3696kb
input:
1 0 ?
output:
C
result:
ok correct
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3572kb
input:
1 0 N
output:
-1
result:
wrong answer returned false