# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863302 | quandlm | Binaria (CCO23_day1problem1) | C++14 | 71 ms | 24884 KiB |
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 file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
#define ll long long
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, a, b) for (int i = (a); i >= (b); --i)
#define pi pair<int,int>
#define ple tuple<int,int,int>
#define fi first
#define se second
#define ii make_pair
#define isz(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e6 + 3;
int n,k,a[N],color[N],sz[N],lab[N],ifact[N];
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;
}
int main () {
file("dynamic");
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
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) << '\n';
}
Compilation message (stderr)
# | 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... |