QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#245057#7662. Kaldorian KnightsYarema#WA 6ms7724kbC++171.4kb2023-11-09 18:17:542023-11-09 18:17:54

Judging History

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

  • [2023-11-09 18:17:54]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:7724kb
  • [2023-11-09 18:17:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int mod = 1000'000'007;

int add(int a, int b)
{
	return a + b < mod ? a + b : a + b - mod;
}
int sub(int a, int b)
{
	return a - b >= 0 ? a - b : a - b + mod;
}
int mult(int a, int b)
{
	return (LL)a * b % mod;
}
const int N = 1'000'447;
int fact[N];

int main()
{
	ios::sync_with_stdio(0); 
	cin.tie(0);
	cout << fixed << setprecision(15);
	
	fact[0] = 1;
	FOR (i, 1, N) fact[i] = mult(fact[i - 1], i);
	
	int n;
	cin >> n;
	int k;
	cin >> k;
	int ans = fact[n];
	int sum = 0;
	VI vec(k);
	VI pref(k);
	FOR (i, 0, k)
	{
		cin >> vec[i];
		pref[i] = fact[vec[i]];
		if (i)
			pref[i] = mult(pref[i], pref[i - 1]);
	}
	
	FOR (i, 0, k)
	{
		int x = vec[i];
		sum += x;
		int l = fact[n - sum];
		int r = fact[sum];
		RFOR (j, i, 0)
		{
			r = sub(r, mult(fact[x], pref[j]));
			x += vec[j];
		}
		int d = mult(l, r);
		//cerr << l << ' ' << r << ' ' << d << '\n';
		ans = sub(ans, d);
	}
	cout << ans << '\n';
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 7712kb

input:

3 0

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 3ms
memory: 7532kb

input:

4 1
3

output:

18

result:

ok single line: '18'

Test #3:

score: 0
Accepted
time: 6ms
memory: 7432kb

input:

4 2
2
1

output:

16

result:

ok single line: '16'

Test #4:

score: 0
Accepted
time: 6ms
memory: 7724kb

input:

10 1
10

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 7492kb

input:

10 10
1
1
1
1
1
1
1
1
1
1

output:

999545489

result:

wrong answer 1st lines differ - expected: '0', found: '999545489'