QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#593597#8776. Not Another Constructive!mzyxTL 4ms3840kbC++201.1kb2024-09-27 14:54:482024-09-27 14:54:49

Judging History

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

  • [2024-09-27 14:54:49]
  • 评测
  • 测评结果:TL
  • 用时:4ms
  • 内存:3840kb
  • [2024-09-27 14:54:48]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3)

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, k;
	cin >> n >> k;
	
	string s;
	cin >> s;
	
	auto dfs = [&](auto &self, int p, int N, int NA, int NAC, string t) -> void {
		if (NAC > k) {
			return;
		}
		
		int q = N + n - p;
		q /= 3;
		q++;
		if (NAC + NA * q + N * q * q + q * q * q < k) {
			return;
		}
		
		if (p == n) {
			if (NAC == k) {
				cout << t << "\n";
				exit(0);
			}
			return;
		}
		
		if (s[p] == '?') {
			self(self, p + 1, N + 1, NA, NAC, t + "N");
			self(self, p + 1, N, NA + N, NAC, t + "A");
			self(self, p + 1, N, NA, NAC + NA, t + "C");
			self(self, p + 1, N, NA, NAC, t + "Q");
		} else if (s[p] == 'N') {
			self(self, p + 1, N + 1, NA, NAC, t + s[p]);
		} else if (s[p] == 'A') {
			self(self, p + 1, N, NA + N, NAC, t + s[p]);
		} else if (s[p] == 'C') {
			self(self, p + 1, N, NA, NAC + NA, t + s[p]);
		} else {
			self(self, p + 1, N, NA, NAC, t + s[p]);
		}
	};
	
	dfs(dfs, 0, 0, 0, 0, "");
	
	cout << -1 << "\n";
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3832kb

input:

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

output:

NNCANNNNNNCNNNNNNNNNNN

result:

ok correct

Test #2:

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

input:

18 0
COUNTINGSATELLITES

output:

COUNTINGSATELLITES

result:

ok correct

Test #3:

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

input:

2 1
??

output:

-1

result:

ok correct

Test #4:

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

input:

1 0
?

output:

N

result:

ok correct

Test #5:

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

input:

1 0
N

output:

N

result:

ok correct

Test #6:

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

input:

1 0
X

output:

X

result:

ok correct

Test #7:

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

input:

1 1
?

output:

-1

result:

ok correct

Test #8:

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

input:

1 1
N

output:

-1

result:

ok correct

Test #9:

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

input:

1 1
X

output:

-1

result:

ok correct

Test #10:

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

input:

2 0
??

output:

NN

result:

ok correct

Test #11:

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

input:

2 0
N?

output:

NN

result:

ok correct

Test #12:

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

input:

2 0
?C

output:

NC

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: 3832kb

input:

2 1
?C

output:

-1

result:

ok correct

Test #15:

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

input:

3 1
???

output:

NAC

result:

ok correct

Test #16:

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

input:

3 1
N??

output:

NAC

result:

ok correct

Test #17:

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

input:

3 1
?A?

output:

NAC

result:

ok correct

Test #18:

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

input:

3 1
??C

output:

NAC

result:

ok correct

Test #19:

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

input:

3 1
NA?

output:

NAC

result:

ok correct

Test #20:

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

input:

3 1
N?C

output:

NAC

result:

ok correct

Test #21:

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

input:

3 1
?AC

output:

NAC

result:

ok correct

Test #22:

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

input:

4 1
????

output:

NANC

result:

ok correct

Test #23:

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

input:

4 1
X???

output:

XNAC

result:

ok correct

Test #24:

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

input:

4 1
???Z

output:

NACZ

result:

ok correct

Test #25:

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

input:

4 1
?AA?

output:

-1

result:

ok correct

Test #26:

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

input:

4 1
N???

output:

NANC

result:

ok correct

Test #27:

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

input:

4 1
?N??

output:

ANAC

result:

ok correct

Test #28:

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

input:

4 1
??N?

output:

NANC

result:

ok correct

Test #29:

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

input:

4 1
???N

output:

NACN

result:

ok correct

Test #30:

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

input:

4 1
A???

output:

ANAC

result:

ok correct

Test #31:

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

input:

4 1
?A??

output:

NANC

result:

ok correct

Test #32:

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

input:

4 1
??A?

output:

NCAC

result:

ok correct

Test #33:

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

input:

4 1
???A

output:

NACA

result:

ok correct

Test #34:

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

input:

4 1
C???

output:

CNAC

result:

ok correct

Test #35:

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

input:

4 1
?C??

output:

NCAC

result:

ok correct

Test #36:

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

input:

4 1
??C?

output:

NACN

result:

ok correct

Test #37:

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

input:

4 1
???C

output:

NANC

result:

ok correct

Test #38:

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

input:

5 4
?????

output:

NNAAC

result:

ok correct

Test #39:

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

input:

6 14
??????

output:

-1

result:

ok correct

Test #40:

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

input:

7 14
???????

output:

-1

result:

ok correct

Test #41:

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

input:

8 43
????????

output:

-1

result:

ok correct

Test #42:

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

input:

9 55
?????????

output:

-1

result:

ok correct

Test #43:

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

input:

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

output:

-1

result:

ok correct

Test #44:

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

input:

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

output:

-1

result:

ok correct

Test #45:

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

input:

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

output:

NNNNANNNNNNC

result:

ok correct

Test #46:

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

input:

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

output:

-1

result:

ok correct

Test #47:

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

input:

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

output:

NNNNANAAACACCC

result:

ok correct

Test #48:

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

input:

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

output:

NNNNNNNANANNNNC

result:

ok correct

Test #49:

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

input:

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

output:

-1

result:

ok correct

Test #50:

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

input:

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

output:

-1

result:

ok correct

Test #51:

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

input:

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

output:

-1

result:

ok correct

Test #52:

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

input:

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

output:

NNNNNNNNNNNNNANCANC

result:

ok correct

Test #53:

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

input:

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

output:

-1

result:

ok correct

Test #54:

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

input:

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

output:

-1

result:

ok correct

Test #55:

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

input:

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

output:

-1

result:

ok correct

Test #56:

score: -100
Time Limit Exceeded

input:

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

output:


result: