QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#498476 | #8776. Not Another Constructive! | c20150005 | WA | 1ms | 6284kb | C++14 | 1.1kb | 2024-07-30 15:23:35 | 2024-07-30 15:23:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;using ll=long long;
int rd(int x=0,char c=getchar()){int f=1;while(!isdigit(c))f=(c^'-'?1:-1),c=getchar();while(isdigit(c))x=x*10+(c^48),c=getchar();return x*f;}
const int N=42,K=1005;
int n,k;
bitset<K> f[N][N][N];
char s[N];
int main(){
n=rd(),k=rd();
if(k>(ll)n/3*n/3*n/3)return puts("-1"),0;
scanf("%s",s+1);for(int i=0;i<=n;i++)f[0][0][i][0]=1;
for(int i=0;i<n;i++)for(int j=0;j<n;j++)for(int c=0;c<=n-i;c++){
if(s[i+1]=='N'||s[i+1]=='?')f[i+1][j+1][c]|=f[i][j][c];
if(s[i+1]=='A'||s[i+1]=='?')f[i+1][j][c]|=(f[i][j][c]<<(j*c));
if(s[i+1]=='C'||s[i+1]=='?')if(c)f[i+1][j][c-1]|=f[i][j][c];
if(s[i+1]!='N'&&s[i+1]!='A'&&s[i+1]!='C'&&s[i+1]!='?')f[i+1][j][c]|=f[i][j][c];
}
int x=0;for(;x<=n;x++)if(f[n][x][0][k])break;
if(x>n)return puts("-1"),0;
int c=0;
for(int i=n;i;i--){
if(s[i]=='N')x--;
if(s[i]=='C')c++;
if(s[i]=='A')k-=c*x;
if(s[i]=='?'){
if(x&&f[i-1][x-1][c][k])s[i]='N',x--;
else if(f[i-1][x][c+1][k])s[i]='C',c++;
else s[i]='A',k-=c*x;
}
}
printf("%s",s+1);;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6284kb
input:
22 2 N??A??????C???????????
output:
NCCACNNNNNCAAAAAAAAAAA
result:
ok correct
Test #2:
score: 0
Accepted
time: 1ms
memory: 5420kb
input:
18 0 COUNTINGSATELLITES
output:
COUNTINGSATELLITES
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
2 1 ??
output:
-1
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
1 0 ?
output:
C
result:
ok correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
1 0 N
output:
N
result:
ok correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
1 0 X
output:
X
result:
ok correct
Test #7:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
1 1 ?
output:
-1
result:
ok correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
1 1 N
output:
-1
result:
ok correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
1 1 X
output:
-1
result:
ok correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
2 0 ??
output:
CC
result:
ok correct
Test #11:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
2 0 N?
output:
NC
result:
ok correct
Test #12:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
2 0 ?C
output:
CC
result:
ok correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
2 1 N?
output:
-1
result:
ok correct
Test #14:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
2 1 ?C
output:
-1
result:
ok correct
Test #15:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
3 1 ???
output:
NAC
result:
ok correct
Test #16:
score: 0
Accepted
time: 0ms
memory: 3928kb
input:
3 1 N??
output:
NAC
result:
ok correct
Test #17:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
3 1 ?A?
output:
NAC
result:
ok correct
Test #18:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
3 1 ??C
output:
NAC
result:
ok correct
Test #19:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
3 1 NA?
output:
NAC
result:
ok correct
Test #20:
score: 0
Accepted
time: 1ms
memory: 3852kb
input:
3 1 N?C
output:
NAC
result:
ok correct
Test #21:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
3 1 ?AC
output:
NAC
result:
ok correct
Test #22:
score: 0
Accepted
time: 0ms
memory: 3972kb
input:
4 1 ????
output:
CNAC
result:
ok correct
Test #23:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
4 1 X???
output:
XNAC
result:
ok correct
Test #24:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
4 1 ???Z
output:
NACZ
result:
ok correct
Test #25:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
4 1 ?AA?
output:
-1
result:
ok correct
Test #26:
score: 0
Accepted
time: 0ms
memory: 3916kb
input:
4 1 N???
output:
NCAC
result:
ok correct
Test #27:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
4 1 ?N??
output:
CNAC
result:
ok correct
Test #28:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
4 1 ??N?
output:
NANC
result:
ok correct
Test #29:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
4 1 ???N
output:
NACN
result:
ok correct
Test #30:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
4 1 A???
output:
ANAC
result:
ok correct
Test #31:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
4 1 ?A??
output:
NACA
result:
ok correct
Test #32:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
4 1 ??A?
output:
CNAC
result:
ok correct
Test #33:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
4 1 ???A
output:
NACA
result:
ok correct
Test #34:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
4 1 C???
output:
CNAC
result:
ok correct
Test #35:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
4 1 ?C??
output:
NCAC
result:
ok correct
Test #36:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
4 1 ??C?
output:
NACA
result:
ok correct
Test #37:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
4 1 ???C
output:
CNAC
result:
ok correct
Test #38:
score: -100
Wrong Answer
time: 0ms
memory: 3688kb
input:
5 4 ?????
output:
-1
result:
wrong answer returned false