QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578917#5519. Count Hamiltonian CycleszqsWA 0ms4952kbC++14966b2024-09-20 22:51:472024-09-20 22:51:47

Judging History

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

  • [2024-09-20 22:51:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4952kb
  • [2024-09-20 22:51:47]
  • 提交

answer

#include <cstdio>
#include <algorithm>

const int mod = 998244353;
int a[1000005], n;
char s[1000005];

int main() {
	int _; scanf("%d", &_);
	while (_ --) {
		scanf("%d%s", &n, s + 1), n <<= 1;
		if (n == 2) {puts("1"); continue;}
		int ans = 748683265, w0 = 1, w1 = 1, b0 = 0, b1 = 0;
		for (int i = 2; i <= n; ++ i)
			if (s[i] == s[1]) {//w0,b0 w1,b1
				if (w0 && w1) ++ w0, ++ w1;
				else if (w0 && b1) -- b1, ++ w1;
				else if (b0 && w1) -- b0, ++ w0;
				else if (b0 && b1) {
					if (b0 == 1) ans = 2ll * ans % mod, -- b0, ++ w0;
					else ans = 1ll * ans * b0 % mod * (b0 - 1) % mod, -- b0, -- b1;
				}
			} else {
				if (b0 && b1) ++ b0, ++ b1;
				else if (b0 && w1) -- w1, ++ b1;
				else if (w0 && b1) -- w0, ++ b0;
				else if (w0 && w1) {
					if (w0 == 1) ans = 2ll * ans % mod, -- w0, ++ b0;
					else ans = 1ll * ans * w0 % mod * (w0 - 1) % mod, -- w0, -- w1;
				}
			}
		printf("%d\n", ans);
	}
	return 0;
}

詳細信息

Test #1:

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

input:

3
2
WWBB
3
WBWBWB
7
WWWWBWBBWWBBBB

output:

1
2
62208

result:

ok 3 number(s): "1 2 62208"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 4952kb

input:

1
1000000
BWBWBBBWWWBWBBBWBBWWWBWBBWWBWBWWWBBBBWBBWWBWBBBWBBBWWBWWBBBBWWWWBWBBWWBBWWWWBBBBWWBWWWWBBBWWBWBWWWBWWBWWBWWBWWBWWWWBWBWWWWWWBWWBWWBWBWBWBWWWBWBBBWBBBWWWBBBWBBBWBBWBWWBBBWWBWBWWWBBBBWBBBWWWBWBBBWBBWWBWBWWBBBWWWWBBWBBBWBBBBBBWBWBWBBBWBBBBBWBBBWWBWBWWBBWWWWBBBBBBBBBWBWWBBBWBWWBBBWBBBBWWBWWBWW...

output:

748683265

result:

wrong answer 1st numbers differ - expected: '3254448', found: '748683265'