QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#79769 | #5519. Count Hamiltonian Cycles | zhangboju | RE | 2ms | 3532kb | C++14 | 762b | 2023-02-20 21:20:39 | 2023-02-20 21:20:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x)
{
x=0;short f=1;char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
x*=f;return;
}
const int N=1e6+5,mod=998244353;
int qpow(int a,int k)
{
int res=1;
while(k)
{
if(k&1) res=1ll*res*a%mod;
a=1ll*a*a%mod;
k>>=1;
}
return res;
}
int n;
char s[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;cin>>T;
while(T--)
{
cin>>n;
cin>>s+1;
int cnt=0,ans=qpow(2,mod-2);
for(int i=1;i<n*2;++i)
{
if(s[i]=='W') ++cnt;
else --cnt;
if(!cnt) ans=2ll*ans%mod;
else ans=1ll*ans*abs(cnt)%mod;
}
cout<<ans<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3532kb
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...