QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#166866 | #5519. Count Hamiltonian Cycles | 275307894a | WA | 25ms | 13784kb | C++14 | 1.2kb | 2023-09-06 19:36:41 | 2023-09-06 19:36:41 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=2e6+5,M=N*20+5,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int n,Sum[N];char s[N];
void Solve(){
int i,j;scanf("%d",&n);
scanf("%s",s+1);
for(i=1;i<=2*n;i++){
Sum[i]=Sum[i-1]+(s[i]=='W'?1:-1);
}
int LA=0,flag=0;
ll ans=1;
for(i=1;i<=2*n;i++) if(!Sum[i]){
int Ct=0;flag++;
for(j=i;j>LA;j--){
if(s[j]==s[i]) Ct++;
else ans=ans*Ct%mod,Ct--;
}
for(j=LA+1;j<i;j++){
if(s[j]^s[i]) Ct++;
else Ct--,ans=ans*Ct%mod;
}
if(i-LA>2) ans=ans*(mod+1)/2%mod;
LA=i;
}
ans=ans*max(1,flag-1)%mod;
printf("%lld\n",ans%mod);
}
int main(){
int t;
scanf("%d",&t);
// t=1;
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4032kb
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: 25ms
memory: 13784kb
input:
1 1000000 BWBWBBBWWWBWBBBWBBWWWBWBBWWBWBWWWBBBBWBBWWBWBBBWBBBWWBWWBBBBWWWWBWBBWWBBWWWWBBBBWWBWWWWBBBWWBWBWWWBWWBWWBWWBWWBWWWWBWBWWWWWWBWWBWWBWBWBWBWWWBWBBBWBBBWWWBBBWBBBWBBWBWWBBBWWBWBWWWBBBBWBBBWWWBWBBBWBBWWBWBWWBBBWWWWBBWBBBWBBBBBBWBWBWBBBWBBBBBWBBBWWBWBWWBBWWWWBBBBBBBBBWBWWBBBWBWWBBBWBBBBWWBWWBWW...
output:
87133535
result:
wrong answer 1st numbers differ - expected: '3254448', found: '87133535'