QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#409786 | #8635. 圆 | Larunatrecy | 20 | 70ms | 3696kb | C++14 | 1.0kb | 2024-05-12 18:31:38 | 2024-05-12 18:31:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n;
const int N = 5050;
int f[N],ifac[N],fac[N];
template <typename T>inline void read(T &x)
{
x=0;char c=getchar();bool f=0;
for(;c<'0'||c>'9';c=getchar())f|=(c=='-');
for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);
x=(f?-x:x);
}
inline int add(int a,int b)
{
return a+b>=mod?a+b-mod:a+b;
}
int Pow(int a,int b)
{
int res=1;
while(b)
{
if(b&1)res=1ll*res*a%mod;
a=1ll*a*a%mod;
b>>=1;
}
return res;
}
int main()
{
cin>>n;
if(n<=3)
{
cout<<1;
return 0;
}
fac[0]=1;
for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
ifac[n]=Pow(fac[n],mod-2);
for(int i=n-1;i>=0;i--)ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
f[1]=0;f[2]=0;
for(int i=3;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
f[i]=add(f[i],1ll*f[i-j]*fac[i-1]%mod*ifac[i-j]%mod);
f[i]=add(f[i],1ll*f[j-1]*fac[i-1]%mod*ifac[j-1]%mod);
f[i]=add(f[i],fac[i-1]);
}
}
cout<<(1ll*f[n-1]*ifac[n-1]%mod+1)%mod<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 0ms
memory: 3540kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 0ms
memory: 3544kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Wrong Answer
time: 1ms
memory: 3444kb
input:
6
output:
3
result:
wrong answer 1st numbers differ - expected: '299473309', found: '3'
Test #4:
score: 0
Wrong Answer
time: 1ms
memory: 3492kb
input:
10
output:
5
result:
wrong answer 1st numbers differ - expected: '487238321', found: '5'
Test #5:
score: 0
Wrong Answer
time: 1ms
memory: 3584kb
input:
100
output:
50
result:
wrong answer 1st numbers differ - expected: '41620761', found: '50'
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 3604kb
input:
200
output:
100
result:
wrong answer 1st numbers differ - expected: '208771764', found: '100'
Test #7:
score: 0
Wrong Answer
time: 1ms
memory: 3652kb
input:
500
output:
250
result:
wrong answer 1st numbers differ - expected: '888621375', found: '250'
Test #8:
score: 0
Wrong Answer
time: 64ms
memory: 3628kb
input:
4798
output:
2399
result:
wrong answer 1st numbers differ - expected: '319137015', found: '2399'
Test #9:
score: 0
Wrong Answer
time: 70ms
memory: 3684kb
input:
4999
output:
499124676
result:
wrong answer 1st numbers differ - expected: '818467659', found: '499124676'
Test #10:
score: 0
Wrong Answer
time: 70ms
memory: 3696kb
input:
5000
output:
2500
result:
wrong answer 1st numbers differ - expected: '142907477', found: '2500'