QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#518994#8776. Not Another Constructive!solar_express#TL 848ms430452kbC++141.2kb2024-08-14 15:11:282024-08-14 15:11:29

Judging History

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

  • [2024-08-14 15:11:29]
  • 评测
  • 测评结果:TL
  • 用时:848ms
  • 内存:430452kb
  • [2024-08-14 15:11:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct NODE{
	int ck,fa;
	char ch;
}node[42][3000000];
int top[42];
int pd[50000000];
int n,k;
string s;
void add(int id,int N,int NA,int NAC,int fa,char ch){
	int ck=N+NA*41+NAC*401*41;
	if(id&&pd[ck]==id)return ;
	if(NAC+NA*(n-id)+N*(n-id)*(n-id)/4+(n-id)*(n-id)*(n-id)/27<k)return ;
	pd[ck]=id;
	top[id]++;
	node[id][top[id]].ck=ck;
	node[id][top[id]].fa=fa;
	node[id][top[id]].ch=ch;
}
void out(int zz,int x){
	if(zz>1){
		out(zz-1,node[zz][x].fa);
	}
	putchar(node[zz][x].ch);
}
int main(){
	cin>>n>>k>>s;
	add(0,0,0,0,0,0);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=top[i-1];j++){
			int N,NA,NAC=node[i-1][j].ck/(401*41);
			NA=node[i-1][j].ck/41-NAC*401;
			N=node[i-1][j].ck-NAC*401*41-NA*41;
			if(s[i-1]=='?'||(s[i-1]!='N'&&s[i-1]!='A'&&s[i-1]!='C'))add(i,N,NA,NAC,j,(s[i-1]=='?')? 'Q':s[i-1]);
			if(s[i-1]=='?'||(s[i-1]=='N'))add(i,N+1,NA,NAC,j,'N');
			if(s[i-1]=='?'||(s[i-1]=='A'))add(i,N,NA+N,NAC,j,'A');
			if(s[i-1]=='?'||(s[i-1]=='C'))add(i,N,NA,NAC+NA,j,'C');
		}
	}
	int ans=0;
	for(int i=1;i<=top[n];i++){
		int NAC=node[n][i].ck/(401*41);
		if(NAC==k){
			out(n,i);
			ans=1;
			break;
		}
	}
	if(!ans)puts("-1");
}

详细

Test #1:

score: 100
Accepted
time: 22ms
memory: 57428kb

input:

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

output:

NQQAQQQQQQCQQQQQQQQQQC

result:

ok correct

Test #2:

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

input:

18 0
COUNTINGSATELLITES

output:

COUNTINGSATELLITES

result:

ok correct

Test #3:

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

input:

2 1
??

output:

-1

result:

ok correct

Test #4:

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

input:

1 0
?

output:

Q

result:

ok correct

Test #5:

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

input:

1 0
N

output:

N

result:

ok correct

Test #6:

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

input:

1 0
X

output:

X

result:

ok correct

Test #7:

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

input:

1 1
?

output:

-1

result:

ok correct

Test #8:

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

input:

1 1
N

output:

-1

result:

ok correct

Test #9:

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

input:

1 1
X

output:

-1

result:

ok correct

Test #10:

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

input:

2 0
??

output:

QQ

result:

ok correct

Test #11:

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

input:

2 0
N?

output:

NQ

result:

ok correct

Test #12:

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

input:

2 0
?C

output:

QC

result:

ok correct

Test #13:

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

input:

2 1
N?

output:

-1

result:

ok correct

Test #14:

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

input:

2 1
?C

output:

-1

result:

ok correct

Test #15:

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

input:

3 1
???

output:

NAC

result:

ok correct

Test #16:

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

input:

3 1
N??

output:

NAC

result:

ok correct

Test #17:

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

input:

3 1
?A?

output:

NAC

result:

ok correct

Test #18:

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

input:

3 1
??C

output:

NAC

result:

ok correct

Test #19:

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

input:

3 1
NA?

output:

NAC

result:

ok correct

Test #20:

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

input:

3 1
N?C

output:

NAC

result:

ok correct

Test #21:

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

input:

3 1
?AC

output:

NAC

result:

ok correct

Test #22:

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

input:

4 1
????

output:

QNAC

result:

ok correct

Test #23:

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

input:

4 1
X???

output:

XNAC

result:

ok correct

Test #24:

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

input:

4 1
???Z

output:

NACZ

result:

ok correct

Test #25:

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

input:

4 1
?AA?

output:

-1

result:

ok correct

Test #26:

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

input:

4 1
N???

output:

NQAC

result:

ok correct

Test #27:

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

input:

4 1
?N??

output:

QNAC

result:

ok correct

Test #28:

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

input:

4 1
??N?

output:

NANC

result:

ok correct

Test #29:

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

input:

4 1
???N

output:

NACN

result:

ok correct

Test #30:

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

input:

4 1
A???

output:

ANAC

result:

ok correct

Test #31:

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

input:

4 1
?A??

output:

NAQC

result:

ok correct

Test #32:

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

input:

4 1
??A?

output:

QNAC

result:

ok correct

Test #33:

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

input:

4 1
???A

output:

NACA

result:

ok correct

Test #34:

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

input:

4 1
C???

output:

CNAC

result:

ok correct

Test #35:

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

input:

4 1
?C??

output:

NCAC

result:

ok correct

Test #36:

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

input:

4 1
??C?

output:

NACQ

result:

ok correct

Test #37:

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

input:

4 1
???C

output:

QNAC

result:

ok correct

Test #38:

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

input:

5 4
?????

output:

NNAAC

result:

ok correct

Test #39:

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

input:

6 14
??????

output:

-1

result:

ok correct

Test #40:

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

input:

7 14
???????

output:

-1

result:

ok correct

Test #41:

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

input:

8 43
????????

output:

-1

result:

ok correct

Test #42:

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

input:

9 55
?????????

output:

-1

result:

ok correct

Test #43:

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

input:

10 112
??????????

output:

-1

result:

ok correct

Test #44:

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

input:

11 110
???????????

output:

-1

result:

ok correct

Test #45:

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

input:

12 4
????????????

output:

QQQQQQQNNAAC

result:

ok correct

Test #46:

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

input:

13 193
?????????????

output:

-1

result:

ok correct

Test #47:

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

input:

14 91
??????????????

output:

NNNNANAAACACCC

result:

ok correct

Test #48:

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

input:

15 15
???????????????

output:

QQQQQQQNNNAACAC

result:

ok correct

Test #49:

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

input:

16 261
????????????????

output:

-1

result:

ok correct

Test #50:

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

input:

17 514
?????????????????

output:

-1

result:

ok correct

Test #51:

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

input:

18 678
??????????????????

output:

-1

result:

ok correct

Test #52:

score: 0
Accepted
time: 10ms
memory: 49676kb

input:

19 40
???????????????????

output:

QQQQQQQQNNNNNAAAACC

result:

ok correct

Test #53:

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

input:

20 1019
????????????????????

output:

-1

result:

ok correct

Test #54:

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

input:

21 1218
?????????????????????

output:

-1

result:

ok correct

Test #55:

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

input:

22 1348
??????????????????????

output:

-1

result:

ok correct

Test #56:

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

input:

23 476
???????????????????????

output:

-1

result:

ok correct

Test #57:

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

input:

24 1445
????????????????????????

output:

-1

result:

ok correct

Test #58:

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

input:

25 1331
?????????????????????????

output:

-1

result:

ok correct

Test #59:

score: 0
Accepted
time: 19ms
memory: 71020kb

input:

26 459
??????????????????????????

output:

QQNNNNNNNNNAAANAAACACCCCCC

result:

ok correct

Test #60:

score: 0
Accepted
time: 31ms
memory: 82888kb

input:

27 398
???????????????????????????

output:

QQQQNNNNNNNNNAANAAAACACCCCC

result:

ok correct

Test #61:

score: 0
Accepted
time: 76ms
memory: 111560kb

input:

28 274
????????????????????????????

output:

QQQQQQQQNNNNNNNANAAAACACCCCC

result:

ok correct

Test #62:

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

input:

29 1624
?????????????????????????????

output:

-1

result:

ok correct

Test #63:

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

input:

30 2079
??????????????????????????????

output:

-1

result:

ok correct

Test #64:

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

input:

31 2067
???????????????????????????????

output:

-1

result:

ok correct

Test #65:

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

input:

32 1267
????????????????????????????????

output:

-1

result:

ok correct

Test #66:

score: 0
Accepted
time: 63ms
memory: 129752kb

input:

33 928
?????????????????????????????????

output:

QQQNNNNNNNNNNNNANAAAAAAAACCCCCCCC

result:

ok correct

Test #67:

score: 0
Accepted
time: 390ms
memory: 278748kb

input:

34 298
??????????????????????????????????

output:

QQQQQQQQQQQQQNNNNNNNANAAAAACCCCACC

result:

ok correct

Test #68:

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

input:

35 2361
???????????????????????????????????

output:

-1

result:

ok correct

Test #69:

score: 0
Accepted
time: 686ms
memory: 344828kb

input:

36 489
????????????????????????????????????

output:

QQQQQQQQQQQQNNNNNNNANAAAAAAACACCCCCC

result:

ok correct

Test #70:

score: 0
Accepted
time: 848ms
memory: 430452kb

input:

37 294
?????????????????????????????????????

output:

QQQQQQQQQQQQQQQQQNNNNNNNAAAAAAACCCCCC

result:

ok correct

Test #71:

score: 0
Accepted
time: 144ms
memory: 184568kb

input:

38 1558
??????????????????????????????????????

output:

QQNNNNNNNNNNNNNNNANAAAAAAAACCACCCCCCCC

result:

ok correct

Test #72:

score: 0
Accepted
time: 406ms
memory: 309148kb

input:

39 1319
???????????????????????????????????????

output:

QQQQQNNNNNNNNNNNNNANAAAAAAACCCCACCCCCCC

result:

ok correct

Test #73:

score: -100
Time Limit Exceeded

input:

40 993
????????????????????????????????????????

output:

QQQQQQQQQNNNNNNNNNNNNANAAAAAAAACCCACCCCC

result: