QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#447772#8721. 括号序列275307894aTL 3ms4040kbC++141.6kb2024-06-18 19:49:262024-06-18 19:49:27

Judging History

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

  • [2024-06-18 19:49:27]
  • 评测
  • 测评结果:TL
  • 用时:3ms
  • 内存:4040kb
  • [2024-06-18 19:49:26]
  • 提交

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
#define eb emplace_back
#define all(x) x.begin(),x.end()
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>;
const int N=2.5e5+5,M=N*4+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n;
ll f[N],g[N],inv[N],frc[N];
void Solve(){
	int i,j;scanf("%d",&n);
	inv[1]=1;for(i=2;i<=n;i++) inv[i]=(mod-inv[mod%i])*(mod/i)%mod;
	for(frc[0]=i=1;i<=n;i++) frc[i]=frc[i-1]*i%mod;
	f[0]=g[0]=1;
	for(i=1;i<=n;i++){
		g[i]=f[i-1];
		for(j=0;j<i-1;j++) g[i]+=f[j]*g[i-j-1]%mod*(i-j-1)%mod;
		g[i]=g[i]%mod*inv[i]%mod;
		for(j=1;j<=i;j++) f[i]+=g[j]*f[i-j]%mod;
		f[i]%=mod;
		gdb(f[i]*frc[i]%mod,g[i]*frc[i]%mod,i);
	}
	printf("%lld\n",f[n]*frc[n]%mod);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 4020kb

input:

3

output:

28

result:

ok 1 number(s): "28"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3956kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3944kb

input:

2

output:

4

result:

ok 1 number(s): "4"

Test #4:

score: 0
Accepted
time: 0ms
memory: 4024kb

input:

4

output:

282

result:

ok 1 number(s): "282"

Test #5:

score: 0
Accepted
time: 0ms
memory: 4040kb

input:

5

output:

3718

result:

ok 1 number(s): "3718"

Test #6:

score: 0
Accepted
time: 1ms
memory: 4012kb

input:

6

output:

60694

result:

ok 1 number(s): "60694"

Test #7:

score: 0
Accepted
time: 0ms
memory: 4020kb

input:

7

output:

1182522

result:

ok 1 number(s): "1182522"

Test #8:

score: 0
Accepted
time: 0ms
memory: 4028kb

input:

8

output:

26791738

result:

ok 1 number(s): "26791738"

Test #9:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

9

output:

692310518

result:

ok 1 number(s): "692310518"

Test #10:

score: 0
Accepted
time: 0ms
memory: 4036kb

input:

10

output:

135061370

result:

ok 1 number(s): "135061370"

Test #11:

score: 0
Accepted
time: 1ms
memory: 4016kb

input:

100

output:

423669705

result:

ok 1 number(s): "423669705"

Test #12:

score: 0
Accepted
time: 3ms
memory: 3944kb

input:

1234

output:

878522960

result:

ok 1 number(s): "878522960"

Test #13:

score: -100
Time Limit Exceeded

input:

54321

output:


result: