QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#593573#8776. Not Another Constructive!mzyxWA 1ms3864kbC++201.1kb2024-09-27 14:44:392024-09-27 14:44:40

Judging History

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

  • [2024-09-27 14:44:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3864kb
  • [2024-09-27 14:44:39]
  • 提交

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 + 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: 1ms
memory: 3792kb

input:

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

output:

NNCANNNNNNCNNNNNNNNNNN

result:

ok correct

Test #2:

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

input:

18 0
COUNTINGSATELLITES

output:

COUNTINGSATELLITES

result:

ok correct

Test #3:

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

input:

2 1
??

output:

-1

result:

ok correct

Test #4:

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

input:

1 0
?

output:

N

result:

ok correct

Test #5:

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

input:

1 0
N

output:

N

result:

ok correct

Test #6:

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

input:

1 0
X

output:

X

result:

ok correct

Test #7:

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

input:

1 1
?

output:

-1

result:

ok correct

Test #8:

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

input:

1 1
N

output:

-1

result:

ok correct

Test #9:

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

input:

1 1
X

output:

-1

result:

ok correct

Test #10:

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

input:

2 0
??

output:

NN

result:

ok correct

Test #11:

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

input:

2 0
N?

output:

NN

result:

ok correct

Test #12:

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

input:

2 0
?C

output:

NC

result:

ok correct

Test #13:

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

input:

2 1
N?

output:

-1

result:

ok correct

Test #14:

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

input:

2 1
?C

output:

-1

result:

ok correct

Test #15:

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

input:

3 1
???

output:

NAC

result:

ok correct

Test #16:

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

input:

3 1
N??

output:

NAC

result:

ok correct

Test #17:

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

input:

3 1
?A?

output:

NAC

result:

ok correct

Test #18:

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

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

input:

3 1
N?C

output:

NAC

result:

ok correct

Test #21:

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

input:

3 1
?AC

output:

NAC

result:

ok correct

Test #22:

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

input:

4 1
????

output:

NANC

result:

ok correct

Test #23:

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

input:

4 1
X???

output:

XNAC

result:

ok correct

Test #24:

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

input:

4 1
???Z

output:

NACZ

result:

ok correct

Test #25:

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

input:

4 1
?AA?

output:

-1

result:

ok correct

Test #26:

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

input:

4 1
N???

output:

NANC

result:

ok correct

Test #27:

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

input:

4 1
?N??

output:

ANAC

result:

ok correct

Test #28:

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

input:

4 1
??N?

output:

NANC

result:

ok correct

Test #29:

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

input:

4 1
???N

output:

NACN

result:

ok correct

Test #30:

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

input:

4 1
A???

output:

ANAC

result:

ok correct

Test #31:

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

input:

4 1
?A??

output:

NANC

result:

ok correct

Test #32:

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

input:

4 1
??A?

output:

NCAC

result:

ok correct

Test #33:

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

input:

4 1
???A

output:

NACA

result:

ok correct

Test #34:

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

input:

4 1
C???

output:

CNAC

result:

ok correct

Test #35:

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

input:

4 1
?C??

output:

NCAC

result:

ok correct

Test #36:

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

input:

4 1
??C?

output:

NACN

result:

ok correct

Test #37:

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

input:

4 1
???C

output:

NANC

result:

ok correct

Test #38:

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

input:

5 4
?????

output:

NNAAC

result:

ok correct

Test #39:

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

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

input:

8 43
????????

output:

-1

result:

ok correct

Test #42:

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

input:

9 55
?????????

output:

-1

result:

ok correct

Test #43:

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

input:

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

output:

-1

result:

ok correct

Test #44:

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

input:

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

output:

-1

result:

ok correct

Test #45:

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

input:

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

output:

NNNNANNNNNNC

result:

ok correct

Test #46:

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

input:

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

output:

-1

result:

ok correct

Test #47:

score: -100
Wrong Answer
time: 1ms
memory: 3548kb

input:

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

output:

-1

result:

wrong answer returned false