QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#578917 | #5519. Count Hamiltonian Cycles | zqs | WA | 0ms | 4952kb | C++14 | 966b | 2024-09-20 22:51:47 | 2024-09-20 22:51:47 |
Judging History
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'