QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#245030#7662. Kaldorian KnightsYarema#WA 6ms7612kbC++171.1kb2023-11-09 18:01:172023-11-09 18:01:18

Judging History

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

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

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;
	FOR (i, 0, k)
	{
		int x;
		cin >> x;
		sum += x;
		int l = fact[n - sum];
		int r = fact[sum];
		if (i)
			r = sub(r, mult(fact[x], fact[sum - x]));
		ans = sub(ans, mult(l, r));
	}
	cout << ans << '\n';
	
	
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 7612kb

input:

3 0

output:

6

result:

ok single line: '6'

Test #2:

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

input:

4 1
3

output:

18

result:

ok single line: '18'

Test #3:

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

input:

4 2
2
1

output:

16

result:

ok single line: '16'

Test #4:

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

input:

10 1
10

output:

0

result:

ok single line: '0'

Test #5:

score: -100
Wrong Answer
time: 6ms
memory: 7524kb

input:

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

output:

999481607

result:

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