QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#430403 | #5519. Count Hamiltonian Cycles | ship2077 | RE | 1ms | 3836kb | C++14 | 376b | 2024-06-03 19:47:43 | 2024-06-03 19:47:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int mod=998244353;
char s[1000005];
void solve(){ int n,ans=1;
scanf("%d%s",&n,s+1);
for (int i=1,tmp=0;i<n<<1;i++){
tmp+=s[i]=='B'?1:-1;
ans=1ll*ans*(tmp?abs(tmp):2)%mod;
}
printf("%d\n",1ll*ans*(mod+1>>1)%mod);
}
int main(){int T;scanf("%d",&T);while (T--) solve();return 0;}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3836kb
input:
3 2 WWBB 3 WBWBWB 7 WWWWBWBBWWBBBB
output:
1 2 62208
result:
ok 3 number(s): "1 2 62208"
Test #2:
score: -100
Runtime Error
input:
1 1000000 BWBWBBBWWWBWBBBWBBWWWBWBBWWBWBWWWBBBBWBBWWBWBBBWBBBWWBWWBBBBWWWWBWBBWWBBWWWWBBBBWWBWWWWBBBWWBWBWWWBWWBWWBWWBWWBWWWWBWBWWWWWWBWWBWWBWBWBWBWWWBWBBBWBBBWWWBBBWBBBWBBWBWWBBBWWBWBWWWBBBBWBBBWWWBWBBBWBBWWBWBWWBBBWWWWBBWBBBWBBBBBBWBWBWBBBWBBBBBWBBBWWBWBWWBBWWWWBBBBBBBBBWBWWBBBWBWWBBBWBBBBWWBWWBWW...