QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#245057 | #7662. Kaldorian Knights | Yarema# | WA | 6ms | 7724kb | C++17 | 1.4kb | 2023-11-09 18:17:54 | 2023-11-09 18:17:54 |
Judging History
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;
}
詳細信息
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'