QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#185173#6736. Alice and Bobteam1041#TL 0ms0kbC++201.2kb2023-09-21 18:28:092023-09-21 18:28:09

Judging History

你现在查看的是最新测评结果

  • [2023-09-21 18:28:09]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-09-21 18:28:09]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);
//#define int long long
#define endl '\n'
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define db double
#define ll long long

using namespace std;
const int N = 1e7+7,mod = 998244353;

ll qmi(ll a, ll b, ll p)
{
	ll res = 1;
	while(b)
	{
		if(b & 1) res = (ll)res * a % p;
		a = (ll)a * a % p;
		b >>= 1;
	}
	return res;
}
// ll qmi(ll x, ll y, ll p)
// {
	// if(y < 0) x = -x, y = -y;
	// ll z = (long double)x / p * y;
	// ll res = (unsigned long long)x*y - (unsigned long long)z * p;
	// return (res + p) % p;
// }
int fa[N],infa[N];
void initcp(int n)
{
	fa[0] = infa[0] = 1;
	rep(i,1,n-1)
	{
		fa[i] = (ll)fa[i-1] * i % mod;
		infa[i] = (ll)infa[i-1] * qmi(i,mod-2,mod)%mod;
	}
}

int P(int a, int b)
{
	if(a < b) return 0;
	return (ll)fa[a] * infa[a-b] % mod;
}

void solve()
{
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i ++)
	{
		ans = (ans + P(n-i,i-1)*fa[n-i]%mod )%mod;
	}
	cout << ans << endl;
}

signed main()
{
	//IOS
	int T = 1;
	initcp(1e7+6);
	//cin >> T;
	while(T--)
	{
		solve();
	}
	
	return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

1

output:

1

result: