QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#412884 | #6736. Alice and Bob | Zhaz | TL | 4ms | 5740kb | C++17 | 1.6kb | 2024-05-16 21:03:25 | 2024-05-16 21:03:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define endl "\n"
#define PII pair<double,int>
const int maxn=1e7+5;
const int mod=998244353;
int dp[maxn],p[maxn];
ll pow(ll a, ll b, ll m)
{
ll ans = 1;
a %= m;
while(b)
{
if(b & 1)ans = (ans % m) * (a % m) % m;
b /= 2;
a = (a % m) * (a % m) % m;
}
ans %= m;
return ans;
}
ll inv(ll x, ll p)//x关于p的逆元,p为素数
{
return pow(x, p - 2, p);
}
ll C(ll n, ll m, ll p)//组合数C(n, m) % p
{
if(m > n)return 0;
ll up = 1, down = 1;//分子分母;
for(int i = n - m + 1; i <= n; i++)up = up * i % p;
for(int i = 1; i <= m; i++)down = down * i % p;
return up * inv(down, p) % p;
}
ll Lucas(ll n, ll m, ll p)
{
if(m == 0)return 1;
return C(n % p, m % p, p) * Lucas(n / p, m / p, p) % p;
}
signed main(){
// ios::sync_with_stdio(false);
// cin.tie(0),cout.tie(0);
int n;cin>>n;
p[1]=1;
dp[1]=1;
dp[2]=1;
dp[3]=3;
// dp[4]=10;
for(int i=2;i<=n;i++){
p[i]=p[i-1]*i;
p[i]%=mod;
}
int ans=p[n-1];
int s=1,x=n-2;
for(int i=2;i<=n;i++){
// int temp=Lucas(x,s,mod)*inv(Lucas(n-1,i-1,mod),mod);
// temp*=p[n-1];
// temp%=mod;
int temp=Lucas(x,s,mod)*p[n-1]%mod;
ans+=temp*inv(Lucas(n-1,i-1,mod),mod);
ans%=mod;
// printf("%d %d %d\n",s,x,p[n-1]);
x--;s++;
if(s>x)break;
}
if(n==1)ans=1;
cout<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5672kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5612kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5668kb
input:
10
output:
997920
result:
ok 1 number(s): "997920"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5676kb
input:
100
output:
188898954
result:
ok 1 number(s): "188898954"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5680kb
input:
4
output:
10
result:
ok 1 number(s): "10"
Test #6:
score: 0
Accepted
time: 1ms
memory: 5680kb
input:
8
output:
12336
result:
ok 1 number(s): "12336"
Test #7:
score: 0
Accepted
time: 0ms
memory: 5668kb
input:
16
output:
373118483
result:
ok 1 number(s): "373118483"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5732kb
input:
32
output:
314585464
result:
ok 1 number(s): "314585464"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5592kb
input:
64
output:
627827331
result:
ok 1 number(s): "627827331"
Test #10:
score: 0
Accepted
time: 0ms
memory: 5680kb
input:
128
output:
828497685
result:
ok 1 number(s): "828497685"
Test #11:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
256
output:
65697890
result:
ok 1 number(s): "65697890"
Test #12:
score: 0
Accepted
time: 2ms
memory: 5616kb
input:
512
output:
854187619
result:
ok 1 number(s): "854187619"
Test #13:
score: 0
Accepted
time: 4ms
memory: 5740kb
input:
1024
output:
513823539
result:
ok 1 number(s): "513823539"
Test #14:
score: -100
Time Limit Exceeded
input:
1361956