#include <iostream>
#include <vector>
using namespace std;
int res[1000005];
int sum[1000005];
const int mod = 1000003;
int mul(int id, int x)
{
if (x == 0) return 1;
long long ans = mul(id, x / 2);
ans = ans * ans % mod;
return (x & 1) ? (ans * id % mod) : ans;
}
int rev(int x)
{
return mul(x, mod - 2);
}
int main()
{
int N, K; cin >> N >> K;
for (int i = 1; i <= N - K + 1; i++) cin >> sum[i];
fill(res, res + 1000005, -1);
for (int i = 1; i <= N - K; i++) {
if (sum[i+1] ^ sum[i]) {
if (sum[i+1] - sum[i] == 1) {
if (res[i+K] != 0) res[i+K] = 1;
else {
cout << "0\n";
return 0;
}
if (res[i] != 1) res[i] = 0;
else {
cout << "0\n";
return 0;
}
}
else {
if (res[i+K] != 1) res[i+K] = 0;
else {
cout << "0\n";
return 0;
}
if (res[i] != 0) res[i] = 1;
else {
cout << "0\n";
return 0;
}
}
}
}
int tot = 0, cur = 0;
for (int i = 1; i <= K; i++) {
if (res[i] == -1) tot++;
if (res[i] == 1) cur++;
}
cur = sum[1] - cur;
if (cur < 0 || cur > tot) cout << "0\n";
else {
long long ans = 1;
for (int i = tot; i >= tot - cur + 1; i--) {
ans = ans * i % mod;
}
for (int i = 1; i <= cur; i++) {
ans = ans * rev(i) % mod;
}
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Incorrect |
1 ms |
4180 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Incorrect |
1 ms |
4180 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Incorrect |
1 ms |
4180 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Incorrect |
1 ms |
4180 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Incorrect |
1 ms |
4180 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Incorrect |
1 ms |
4180 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |