QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#590933 | #8635. 圆 | BreakPlus | 100 ✓ | 112ms | 438576kb | C++14 | 1.4kb | 2024-09-26 13:10:11 | 2024-09-26 13:10:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pr;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
#define mid ((l+r)>>1)
#define popcnt __builtin_popcountll
const ll mod = 998244353;
inline ll read(){
ll x=0, f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
return x*f;
}
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline ll qpow(ll a,ll b){
ll ans=1, base=a;
while(b){
if(b&1) ans=ans*base%mod;
base=base*base%mod; b>>=1;
}
return ans;
}
void init(){ }
ll n,f[4][5005][5005];
void procedure(){
n=read();
f[1][1][1]=1; f[2][2][1]=1; f[3][3][1]=1;
for(ll p=1;p<=3;p++)
for(ll i=p+1;i<=n;i++){
for(ll j=2;j<=i;j++){
f[p][i][j]=(f[p][i-1][j-1]+f[p][i-2][j-1])%mod;
if(i>3) f[p][i][j]=(f[p][i][j]+f[p][i-3][j-1])%mod;
}
}
ll ans=1, now=1;
for(ll k=1;k<=n;k++){
ll coef=(f[1][n][k]+f[1][n-1][k]+f[1][n-2][k]+f[2][n][k]+f[2][n-1][k]+f[3][n][k])%mod;
// cout<<"choose "<<k<<" full: "<<coef<<endl;
now=now*(n-k+1)%mod*qpow(k,mod-2)%mod;
ans=(ans+(now+mod-coef)*qpow(now,mod-2))%mod;
}
printf("%lld\n", ans);
}
int main(){
#ifdef LOCAL
assert(freopen("input.txt","r",stdin));
assert(freopen("output.txt","w",stdout));
#endif
ll T=1;
init();
while(T--) procedure();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 2ms
memory: 9980kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 0ms
memory: 9892kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 2ms
memory: 9976kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 0ms
memory: 11936kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 0ms
memory: 20216kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 0ms
memory: 30456kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 3ms
memory: 69468kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 51ms
memory: 426084kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 112ms
memory: 438220kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 96ms
memory: 438576kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"