QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#639931#8776. Not Another Constructive!TenshiWA 48ms112556kbC++232.2kb2024-10-14 00:06:012024-10-14 00:06:02

Judging History

你现在查看的是最新测评结果

  • [2024-10-14 00:06:02]
  • 评测
  • 测评结果:WA
  • 用时:48ms
  • 内存:112556kb
  • [2024-10-14 00:06:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << ": " << (x) << endl
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
 
#define x first
#define y second
using pii = pair<int, int>;
using ll = long long;
 
inline void read(int &x){
    int s=0; x=1;
    char ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-')x=-1;ch=getchar();}
    while(ch>='0' && ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
    x*=s;
}

const int N=13*13*14+5;

int n, K;
string s;
bitset<N> f[41][41][401];

void print(int idx, int a, int b, int c){
	if(!idx) return;
	int pi, pa, pb, pc;
	char res, cur=s[idx];
	if(cur=='N'){
		pi=idx-1, pa=a-1, pb=b, pc=c;
	}
	else if(cur=='A'){
		pi=idx-1, pa=a, pb=b-a, pc=c;
	}
	else if(cur=='C'){
		pi=idx-1, pa=a, pb=b, pc=c-b;
	}
	else if(isalpha(cur)){
		pi=idx-1, pa=a, pb=b, pc=c;
	}
	else{
		if(f[idx-1][a-1][b][c]) pi=idx-1, pa=a-1, pb=b, pc=c, res='N';
		else if(f[idx-1][a][b-a][c]) pi=idx-1, pa=a, pb=b-a, pc=c, res='A';
		else if(f[idx-1][a][b][c-b]) pi=idx-1, pa=a, pb=b, pc=c-b, res='C';
		else if(f[idx-1][a][b][c]) pi=idx-1, pa=a, pb=b, pc=c, res='T';
	}
	
	if(isalpha(cur)) res=cur;
	
	print(pi, pa, pb, pc);
	
	putchar(res);
}

signed main(){
	cin>>n>>K;
	cin>>s;
	s=" "+s;
	
	// debug(sizeof f);
	
	f[0][0][0][0]=1;
	rep(i, 1, n){
		char c=s[i];
		if(c=='N'){
			rep(a, 1, 40) rep(b, 0, 400) f[i][a][b]=f[i-1][a-1][b]; 
		}
		else if(c=='A'){
			rep(a, 0, 40) rep(b, a, 400) f[i][a][b]=f[i-1][a][b-a];
		}
		else if(c=='C'){
			rep(a, 0, 40) rep(b, 0, 400) f[i][a][b]=f[i-1][a][b]>>b;
		}
		else if(isalpha(c)){
			rep(a, 0, 40) rep(b, 0, 400) f[i][a][b]=f[i-1][a][b];
		}
		else{
			rep(a, 0, 40) rep(b, 0, 400) f[i][a][b]=f[i-1][a][b];
			rep(a, 1, 40) rep(b, 0, 400) f[i][a][b]|=f[i-1][a-1][b]; 
			rep(a, 0, 40) rep(b, a, 400) f[i][a][b]|=f[i-1][a][b-a];
			rep(a, 0, 40) rep(b, 0, 400) f[i][a][b]|=f[i-1][a][b]<<b;
		}
	}
	
	int A=-1, B;
	rep(a, 0, 40) rep(b, 0, 400) if(f[n][a][b][K]){
		A=a, B=b;
	}
	if(A==-1){
		puts("-1");
		return 0;
	}
	
	print(n, A, B, K);
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 48ms
memory: 112556kb

input:

22 2
N??A??????C???????????

output:

NCCAANNNNNCNNNNNNNNNNN

result:

ok correct

Test #2:

score: 0
Accepted
time: 8ms
memory: 93952kb

input:

18 0
COUNTINGSATELLITES

output:

COUNTINGSATELLITES

result:

ok correct

Test #3:

score: 0
Accepted
time: 0ms
memory: 16072kb

input:

2 1
??

output:

-1

result:

ok correct

Test #4:

score: 0
Accepted
time: 4ms
memory: 9740kb

input:

1 0
?

output:

N

result:

ok correct

Test #5:

score: 0
Accepted
time: 0ms
memory: 9636kb

input:

1 0
N

output:

N

result:

ok correct

Test #6:

score: 0
Accepted
time: 0ms
memory: 9860kb

input:

1 0
X

output:

X

result:

ok correct

Test #7:

score: 0
Accepted
time: 4ms
memory: 9700kb

input:

1 1
?

output:

-1

result:

ok correct

Test #8:

score: 0
Accepted
time: 2ms
memory: 11844kb

input:

1 1
N

output:

-1

result:

ok correct

Test #9:

score: 0
Accepted
time: 1ms
memory: 9932kb

input:

1 1
X

output:

-1

result:

ok correct

Test #10:

score: 0
Accepted
time: 6ms
memory: 15780kb

input:

2 0
??

output:

NN

result:

ok correct

Test #11:

score: 0
Accepted
time: 2ms
memory: 15908kb

input:

2 0
N?

output:

NN

result:

ok correct

Test #12:

score: 0
Accepted
time: 2ms
memory: 15844kb

input:

2 0
?C

output:

NC

result:

ok correct

Test #13:

score: 0
Accepted
time: 4ms
memory: 15876kb

input:

2 1
N?

output:

-1

result:

ok correct

Test #14:

score: 0
Accepted
time: 6ms
memory: 15904kb

input:

2 1
?C

output:

-1

result:

ok correct

Test #15:

score: 0
Accepted
time: 7ms
memory: 19992kb

input:

3 1
???

output:

NAC

result:

ok correct

Test #16:

score: 0
Accepted
time: 9ms
memory: 20132kb

input:

3 1
N??

output:

NAC

result:

ok correct

Test #17:

score: 0
Accepted
time: 7ms
memory: 22224kb

input:

3 1
?A?

output:

NAC

result:

ok correct

Test #18:

score: -100
Wrong Answer
time: 7ms
memory: 22048kb

input:

3 1
??C

output:

-1

result:

wrong answer returned false