QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#591206 | #8635. 圆 | sunnygreen | 100 ✓ | 55ms | 3768kb | C++14 | 2.0kb | 2024-09-26 14:46:10 | 2024-09-26 14:46:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define fi first
#define se second
#define mk make_pair
#define eb emplace_back
#define rep(i,l,r) for(int i=(l); i<=(r); ++i)
#define rep_(i,l,r) for(int i=(l); i>=(r); --i)
typedef long long lr;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
constexpr int mod1=998244353,mod2=1e9+7;
constexpr db pi=3.141592653589793,eps=1e-9;
constexpr int inf32=0x3f3f3f3f,Inf32=0xc0c0c0c0;
constexpr lr inf64=0x3f3f3f3f3f3f3f3f,Inf64=0xc0c0c0c0c0c0c0c0;
template<typename T>il T Max(T x,T y) { return (x>y)? x:y; }
template<typename T>il T Min(T x,T y) { return (x<y)? x:y; }
template<typename T>il T gcd(T x,T y) { return (!y)? x:gcd(y,x%y); }
template<typename T>il T Abs(T x) { return (x>0)? x:(-x); }
template<typename T>il T Rnd(T l,T r,mt19937_64 &eng)
{
uniform_int_distribution<T> uid(l,r);
return uid(eng);
}
mt19937_64 eng(chrono::high_resolution_clock::now().time_since_epoch().count());
constexpr int N=5050,mod=mod1;
int n,p[N],fac[N],inv[N];
il int Poww(int x,int y)
{
int mul=1;
while(y)
{
if(y&1)
mul=(lr)mul*x%mod;
x=(lr)x*x%mod,y>>=1;
}
return mul;
}
il int C(int x,int y) { return (x<y)? 0:((lr)fac[x]*inv[y]%mod*inv[x-y]%mod); }
il void Solve()
{
cin>>n;
fac[0]=1;
rep(i,1,n)
fac[i]=(lr)fac[i-1]*i%mod;
inv[n]=Poww(fac[n],mod-2);
rep_(i,n,1)
inv[i-1]=(lr)inv[i]*i%mod;
p[0]=1;
rep(i,1,n)
{
int sum=C(n-1,i-1),now=0;
rep(j,1,i)
{
int cur=(lr)C(i,j)*C(n-3*j-1,i-1)%mod;
if(j&1)
now=(now+cur)%mod;
else
now=(now-cur+mod)%mod;
}
p[i]=(lr)now*Poww(sum,mod-2)%mod;
}
int ans=0;
rep(i,1,n)
ans=(ans+(lr)i*(p[i-1]-p[i]))%mod;
cout<<ans<<'\n';
}
int main()
{
#ifdef LOCAL
string fpre="test",isuf="in",osuf="out";
assert(freopen((fpre+"."+isuf).c_str(),"r",stdin));
assert(freopen((fpre+"."+osuf).c_str(),"w",stdout));
#endif
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
while(T--)
Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3568kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 0ms
memory: 3576kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 0ms
memory: 3716kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 0ms
memory: 3716kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 0ms
memory: 3708kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 0ms
memory: 3708kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 1ms
memory: 3696kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 51ms
memory: 3728kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 55ms
memory: 3672kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 55ms
memory: 3768kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"