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 ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
const int mod = 1e6 + 3;
void test_case() {
int n, k;
cin >> n >> k;
vector<int> a(n - k + 1);
for (int &x : a) cin >> x;
vector<vector<ar<int, 2>>> adj(n);
for (int i = 0; i < n-k; i++) {
int w = a[i] != a[i+1];
adj[i].push_back({i + k, w});
adj[i + k].push_back({i, w});
}
int ans = 0;
for (int m = 0; m < 1 << k; m++) if (__builtin_popcount(m) == a[0]) {
vector<bool> vis(n), col(n);
for (int i = 0; i < k; i++) col[i] = m >> i & 1;
bool ok = 1;
auto dfs = [&](auto&& s, int v) -> void {
vis[v] = 1;
for (auto [u, w] : adj[v]) {
int nxt = col[v] ^ w;
if (!vis[u]) {
col[u] = nxt;
s(s, u);
}
else {
if (col[u] != nxt) {
ok = 0;
}
}
}
};
for (int i = 0; i < n; i++) if (!vis[i]) dfs(dfs, i);
vector<int> pref(n);
for (int i = 0; i < n; i++) pref[i] = col[i] + (i ? pref[i-1] : 0);
for (int i = 0; i < n-k+1; i++) {
if (pref[i+k-1] - (i ? pref[i-1] : 0) != a[i]) {
ok = 0; break;
}
}
ans += ok;
}
cout << ans % mod << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while (t--) test_case();
}
# | 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... |