QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#619181 | #8635. 圆 | Augenstern | 100 ✓ | 97ms | 241660kb | C++14 | 1.7kb | 2024-10-07 13:26:31 | 2024-10-07 13:26:31 |
Judging History
answer
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define int long long
//#define ull unsigned long long
#define lll __int128
//#define double long double
using namespace std;
const long long INF=1e16+5;
const long long mod=998244353,orm=3;
//const long long mod=1000000007;
const int MAXN=1000005;
const double eps=1e-6;
bool ST;
int n;
int fac[MAXN],inv[MAXN];
int f[5005][5005],g[5005][5005];
int qp(int x,int y) {
int res=1;
while(y) {
if(y&1) y--,res*=x,res%=mod;
y>>=1,x*=x,x%=mod;
}
return res;
}
void add(int &x,int y) {
x+=y,x%=mod;
}
void solve() {
cin>>n;
fac[0]=inv[0]=1;
for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
for(int i=1;i<=n;i++) inv[i]=inv[i-1]*qp(n-i+1,mod-2)%mod;
f[0][0]=1;
for(int i=1;i<=n-4;i++) {
for(int j=1;j<=i;j++) {
add(f[i][j],f[i-1][j-1]);
if(i>=2) add(f[i][j],f[i-2][j-1]);
if(i>=3) add(f[i][j],f[i-3][j-1]);
}
}
g[1][1]=1,g[2][1]=1,g[2][2]=1;
for(int i=3;i<=n-3;i++) {
for(int j=1;j<=i;j++) {
add(g[i][j],g[i-1][j-1]);
if(i>=2) add(g[i][j],g[i-2][j-1]);
if(i>=3) add(g[i][j],g[i-3][j-1]);
}
}
int res=0;
for(int i=0;i<=n-3;i++) {
int val=g[n-3][i];
if(n>=4) val+=g[n-4][i],val%=mod;
if(n==3) val=1;
res+=fac[i]*val%mod*(i+1)%mod*inv[i+1]%mod,res%=mod;
}
if(n>=4) {
for(int i=0;i<=n-4;i++) {
res+=fac[i+1]*f[n-4][i]%mod*(i+2)%mod*inv[i+2]%mod*2,res%=mod;
}
}
res*=n,res%=mod;
cout<<res;
}
bool ED;
signed main() {
// cout<<(&ST-&ED)/1024.0/1024.0;
// freopen("color.in","r",stdin);
// freopen("color.out","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 1ms
memory: 9856kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 1ms
memory: 9856kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 1ms
memory: 9748kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 0ms
memory: 9756kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 0ms
memory: 10480kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 2ms
memory: 11516kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 0ms
memory: 15584kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 67ms
memory: 227048kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 97ms
memory: 241660kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 87ms
memory: 241272kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"