QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#79769#5519. Count Hamiltonian CycleszhangbojuRE 2ms3532kbC++14762b2023-02-20 21:20:392023-02-20 21:20:41

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-20 21:20:41]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3532kb
  • [2023-02-20 21:20:39]
  • 提交

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";
	}
}

詳細信息

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...

output:


result: