QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#619745 | #8635. 圆 | DanielQOJ | 100 ✓ | 210ms | 3964kb | C++20 | 1.8kb | 2024-10-07 15:14:50 | 2024-10-07 15:14:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod (int)(998244353)
int fac[10005], inv[10005], invfac[10005];
int C(int n, int m){
if(n < m || min(n, m) < 0)return 0;
return fac[n] * invfac[m] % mod * invfac[n - m] % mod;
}
int ksm(int x, int y){
int ans = 1;
while(y){
if(y&1)ans = ans * x % mod;
x = x * x % mod;
y >>= 1;
}
return ans;
}
int f[5005];
int calc(int sum, int n){
int res = 0;
for(int no = 0; no <= n; no++){
f[no] = C(n, no) * C(sum - no * 3 + n - 1, n - 1) % mod;
if(no&1)res -= f[no];
else res += f[no];
}
res %= mod;
return res;
}
int dp[5005];
signed main(){
// freopen("color.in", "r", stdin);
// freopen("color.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
fac[0] = invfac[0] = 1;
fac[1] = invfac[1] = 1;
inv[1] = 1;
for(int i = 2; i <= 10000; i++){
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - (mod / i) * inv[mod % i] % mod;
invfac[i] = invfac[i - 1] * inv[i] % mod;
}
int n;
cin >> n;
if(n == 3){
cout << 1 << '\n';
return 0;
}
int ans = 0;
for(int l = 0; l < 3; l++){
for(int r = 0; r < 3; r++){
if(l + r < 2)continue;
if(l + r + 2 == n)dp[2]++;
for(int num = 2; ; num++){
if(num + l + r + 1 > n)break;
int res = calc(n - l - r - 1 - num, num - 1);
dp[num + 1] += res * fac[num] % mod;
}
}
}
for(int i = 1; i <= n; i++)dp[i] *= n;
for(int i = 1; i <= n; i++){
ans += dp[i] % mod * i % mod * invfac[n] % mod * fac[n - i] % mod;
ans %= mod;
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 1ms
memory: 3876kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 10
Accepted
time: 1ms
memory: 3756kb
input:
4
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 10
Accepted
time: 1ms
memory: 3888kb
input:
6
output:
299473309
result:
ok 1 number(s): "299473309"
Test #4:
score: 10
Accepted
time: 1ms
memory: 3892kb
input:
10
output:
487238321
result:
ok 1 number(s): "487238321"
Test #5:
score: 10
Accepted
time: 1ms
memory: 3884kb
input:
100
output:
41620761
result:
ok 1 number(s): "41620761"
Test #6:
score: 10
Accepted
time: 1ms
memory: 3868kb
input:
200
output:
208771764
result:
ok 1 number(s): "208771764"
Test #7:
score: 10
Accepted
time: 2ms
memory: 3836kb
input:
500
output:
888621375
result:
ok 1 number(s): "888621375"
Test #8:
score: 10
Accepted
time: 183ms
memory: 3964kb
input:
4798
output:
319137015
result:
ok 1 number(s): "319137015"
Test #9:
score: 10
Accepted
time: 210ms
memory: 3896kb
input:
4999
output:
818467659
result:
ok 1 number(s): "818467659"
Test #10:
score: 10
Accepted
time: 158ms
memory: 3892kb
input:
5000
output:
142907477
result:
ok 1 number(s): "142907477"