This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Dit me fryingduc
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fore(i, a, b) for (int i = (a); i <= (b); i++)
#define pb emplace_back
const int mod = 1e6 + 3;
int binpow(int a, int b)
{
if (b == 0) return 1ll;
int ans = binpow(a, b / 2ll);
return ans * ans % mod * (b & 1ll ? a : 1ll) % mod;
}
int nCk(int n, int k)
{
int ans = 1;
if (k > n || n < 0 || k < 0) return 0;
fore(i, k + 1, n) ans = ans * i % mod;
fore(i, 1, n - k) ans = ans * binpow(i, mod - 2) % mod;
return ans;
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<int> a(n - k + 2), x(n + 1, -1);
fore(i, 1, n - k + 1) cin >> a[i];
fore(i, 2, n - k + 1) if (abs(a[i] - a[i - 1]) > 1) return cout << 0, 0;
fore(i, 2, n - k + 1)
{
if (a[i] - a[i - 1] == 1)
x[i + k - 1] = 1,
x[i - 1] = 0;
else if (a[i] - a[i - 1] == -1)
x[i + k - 1] = 0,
x[i - 1] = 1;
else
x[i + k - 1] = x[i - 1];
}
for (int i = n - k; i >= 1; i--)
if (a[i] == a[i + 1])
x[i] = x[i + k];
int use = 0;
fore(i, 1, k)
use += (x[i] == -1),
a[1] -= (x[i] == 1);
cout << nCk(use, a[1]);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |