This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
#define MASK(n) (1 << (n))
#define BIT(mask,x) ((mask >> (x)) & 1)
#define TASK "task"
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
const int mxN = 1e6 + 7;
const int base = 512;
const int inf = 1e9 + 6969;
const int Mod = 1e6 + 3;
const long long infll = 1e18 + 6969;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int n,k,a[mxN],color[mxN],sz[mxN],lab[mxN],ifact[mxN];
void pre_calc () {
ifact[0] = 1;
FOR(i,1,n+10) {
color[i] = -1;
sz[i] = 1;
lab[i] = i;
ifact[i] = 1ll * ifact[i-1] * i % Mod;
}
}
int find (int u) {
return (lab[u] == u ? u : lab[u] = find(lab[u]));
}
bool join (int u, int v) {
u = find(u);
v = find(v);
if (u == v) return false;
if (sz[u] < sz[v]) swap(u, v);
lab[v] = u;
sz[u] += sz[v];
if (color[v] == -1) color[v] = color[u];
return true;
}
int pow_mod (int a, int b) {
if (b == 0) return 1;
if (b == 1) return a;
int res = pow_mod(a, b/2);
res = 1ll * res * res % Mod;
if (b & 1) res = 1ll * res * a % Mod;
return res;
}
int C (int k, int n) {
int A = ifact[n];
int B = 1ll * ifact[n - k] * ifact[k] % Mod;
return 1ll * A * pow_mod(B, Mod - 2) % Mod;
}
void solve() {
cin >> n >> k;
FOR(i,1,n-k+1) cin >> a[i];
pre_calc();
FOR(i,1,n-k) {
if(a[i] == a[i+1]) {
join(i, i + k);
} else if (a[i] > a[i+1]) {
color[find(i)] = 1;
color[find(i + k)] = 0;
} else {
color[find(i)] = 0;
color[find(i + k)] = 1;
}
}
int cnt = 0;
for (int i=1; i<=k; ++i) {
int c = color[find(i)];
if (c != -1) a[1] -= c;
else ++cnt;
}
cout << C(a[1], cnt);
}
signed main() {
ios_base :: sync_with_stdio(0);
cin.tie(0);
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
int tc = 1;
//cin >> tc;
while(tc--) {
solve();
}
}
# | 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... |