#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define file(name) \
if(fopen(name".inp", "r")) \
freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
const int Mod = 1e6 + 3;
const int MAX = 1e6 + 5;
inline void add(int &x, int y) {
x += y;
if(x >= Mod) x -= Mod;
if(x < 0) x += Mod;
}
int n, k, a[MAX];
namespace sub1 {
bool check() {
return n <= 10;
}
void solve() {
int ans = 0;
for (int mask = 0; mask < (1 << n); ++mask) {
bool oke = true;
int sum = 0;
for (int i = 0; i < n; ++i) {
sum += (mask >> i & 1);
if(i >= k) sum -= (mask >> (i - k) & 1);
if(i + 1 >= k) oke &= a[i + 1 - k] == sum;
}
ans += oke;
}
cout << ans; exit(0);
}
}
namespace sub2 {
bool check() {
return n <= 1000 && k <= 10;
}
int dp[1005][1 << 10];
void solve() {
for (int mask = 0; mask < (1 << k); ++mask) {
if(__builtin_popcount(mask) == a[0]) dp[0][mask] = 1;
}
for (int i = 0; i < n - k; ++i) {
for (int mask = 0; mask < (1 << k); ++mask) {
int m0 = (mask << 1) & ((1 << k) - 1);
int m1 = (mask << 1 | 1) & ((1 << k) - 1);
if(__builtin_popcount(m0) == a[i + 1]) add(dp[i + 1][m0], dp[i][mask]);
if(__builtin_popcount(m1) == a[i + 1]) add(dp[i + 1][m1], dp[i][mask]);
}
}
cout << accumulate(dp[n - k], dp[n - k] + (1 << k), 0LL) % Mod;
}
}
namespace sub3 {
int binpow(int n, int exp) {
int ans = 1, mul = n;
for (; exp; exp >>= 1) {
if(exp & 1) ans = 1LL * ans * mul % Mod;
mul = 1LL * mul * mul % Mod;
}
return ans;
}
int color[MAX], lab[MAX];
int find(int u) {
return lab[u] < 0 ? u : lab[u] = find(lab[u]);
}
bool merge(int u, int v) {
u = find(u), v = find(v);
if(u == v) return false;
if(lab[u] > lab[v]) swap(u, v);
lab[u] += lab[v];
lab[v] = u;
if(color[v] == -1) color[v] = color[u];
return true;
}
int C(int k, int n) {
int a = 1, b = 1;
for (int i = n - k + 1; i <= n; ++i) {
b = 1LL * b * (i - n + k) % Mod;
a = 1LL * a * i % Mod;
}
return 1LL * a * binpow(b, Mod - 2) % Mod;
}
void solve() {
fill(color, color + n + 1, -1);
fill(lab, lab + n + 1, -1);
for (int i = 0; i < n - k; ++i) {
if(a[i] == a[i + 1]) {
merge(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 m = a[0], cnt = 0;
for (int i = 0; i < k; ++i) {
int c = color[find(i)];
if(c != -1) m -= c;
else cnt++;
}
cout << C(m, cnt); exit(0);
}
}
void you_make_it(void) {
cin >> n >> k;
for (int i = 0; i < n - k + 1; ++i) cin >> a[i];
reverse(a, a + n - k + 1);
sub3::solve();
if(sub1::check()) sub1::solve();
if(sub2::check()) sub2::solve();
}
signed main() {
#ifdef LOCAL
freopen("TASK.inp", "r", stdin);
freopen("TASK.out", "w", stdout);
#endif
file("CCO23_day1problem1");
auto start_time = chrono::steady_clock::now();
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
you_make_it();
auto end_time = chrono::steady_clock::now();
cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;
return (0 ^ 0);
}
// Dream it. Wish it. Do it.
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:143:4: note: in expansion of macro 'file'
143 | file("CCO23_day1problem1");
| ^~~~
Main.cpp:10:49: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:143:4: note: in expansion of macro 'file'
143 | file("CCO23_day1problem1");
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4440 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4440 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
42 ms |
13908 KB |
Output is correct |
36 |
Correct |
49 ms |
16612 KB |
Output is correct |
37 |
Correct |
55 ms |
16980 KB |
Output is correct |
38 |
Correct |
50 ms |
16980 KB |
Output is correct |
39 |
Correct |
46 ms |
16368 KB |
Output is correct |
40 |
Correct |
48 ms |
16980 KB |
Output is correct |
41 |
Correct |
48 ms |
16976 KB |
Output is correct |
42 |
Correct |
44 ms |
16316 KB |
Output is correct |
43 |
Correct |
44 ms |
15952 KB |
Output is correct |
44 |
Correct |
45 ms |
15860 KB |
Output is correct |
45 |
Correct |
42 ms |
16056 KB |
Output is correct |
46 |
Correct |
44 ms |
15960 KB |
Output is correct |
47 |
Correct |
43 ms |
16020 KB |
Output is correct |
48 |
Correct |
48 ms |
17076 KB |
Output is correct |
49 |
Correct |
48 ms |
16872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4440 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
42 ms |
13908 KB |
Output is correct |
36 |
Correct |
49 ms |
16612 KB |
Output is correct |
37 |
Correct |
55 ms |
16980 KB |
Output is correct |
38 |
Correct |
50 ms |
16980 KB |
Output is correct |
39 |
Correct |
46 ms |
16368 KB |
Output is correct |
40 |
Correct |
48 ms |
16980 KB |
Output is correct |
41 |
Correct |
48 ms |
16976 KB |
Output is correct |
42 |
Correct |
44 ms |
16316 KB |
Output is correct |
43 |
Correct |
44 ms |
15952 KB |
Output is correct |
44 |
Correct |
45 ms |
15860 KB |
Output is correct |
45 |
Correct |
42 ms |
16056 KB |
Output is correct |
46 |
Correct |
44 ms |
15960 KB |
Output is correct |
47 |
Correct |
43 ms |
16020 KB |
Output is correct |
48 |
Correct |
48 ms |
17076 KB |
Output is correct |
49 |
Correct |
48 ms |
16872 KB |
Output is correct |
50 |
Correct |
57 ms |
18872 KB |
Output is correct |
51 |
Correct |
57 ms |
18872 KB |
Output is correct |
52 |
Correct |
58 ms |
19024 KB |
Output is correct |
53 |
Correct |
59 ms |
19024 KB |
Output is correct |
54 |
Correct |
58 ms |
19024 KB |
Output is correct |
55 |
Correct |
60 ms |
19280 KB |
Output is correct |
56 |
Correct |
69 ms |
19008 KB |
Output is correct |
57 |
Correct |
54 ms |
17992 KB |
Output is correct |
58 |
Correct |
58 ms |
19032 KB |
Output is correct |
59 |
Correct |
58 ms |
19000 KB |
Output is correct |
60 |
Correct |
54 ms |
17856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4440 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
4444 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
42 ms |
13908 KB |
Output is correct |
36 |
Correct |
49 ms |
16612 KB |
Output is correct |
37 |
Correct |
55 ms |
16980 KB |
Output is correct |
38 |
Correct |
50 ms |
16980 KB |
Output is correct |
39 |
Correct |
46 ms |
16368 KB |
Output is correct |
40 |
Correct |
48 ms |
16980 KB |
Output is correct |
41 |
Correct |
48 ms |
16976 KB |
Output is correct |
42 |
Correct |
44 ms |
16316 KB |
Output is correct |
43 |
Correct |
44 ms |
15952 KB |
Output is correct |
44 |
Correct |
45 ms |
15860 KB |
Output is correct |
45 |
Correct |
42 ms |
16056 KB |
Output is correct |
46 |
Correct |
44 ms |
15960 KB |
Output is correct |
47 |
Correct |
43 ms |
16020 KB |
Output is correct |
48 |
Correct |
48 ms |
17076 KB |
Output is correct |
49 |
Correct |
48 ms |
16872 KB |
Output is correct |
50 |
Correct |
57 ms |
18872 KB |
Output is correct |
51 |
Correct |
57 ms |
18872 KB |
Output is correct |
52 |
Correct |
58 ms |
19024 KB |
Output is correct |
53 |
Correct |
59 ms |
19024 KB |
Output is correct |
54 |
Correct |
58 ms |
19024 KB |
Output is correct |
55 |
Correct |
60 ms |
19280 KB |
Output is correct |
56 |
Correct |
69 ms |
19008 KB |
Output is correct |
57 |
Correct |
54 ms |
17992 KB |
Output is correct |
58 |
Correct |
58 ms |
19032 KB |
Output is correct |
59 |
Correct |
58 ms |
19000 KB |
Output is correct |
60 |
Correct |
54 ms |
17856 KB |
Output is correct |
61 |
Correct |
5 ms |
10840 KB |
Output is correct |
62 |
Correct |
5 ms |
10844 KB |
Output is correct |
63 |
Correct |
7 ms |
10844 KB |
Output is correct |
64 |
Correct |
5 ms |
10840 KB |
Output is correct |
65 |
Correct |
36 ms |
16320 KB |
Output is correct |
66 |
Correct |
27 ms |
15184 KB |
Output is correct |
67 |
Correct |
56 ms |
18624 KB |
Output is correct |
68 |
Correct |
8 ms |
11096 KB |
Output is correct |
69 |
Correct |
7 ms |
10704 KB |
Output is correct |
70 |
Correct |
2 ms |
10844 KB |
Output is correct |
71 |
Correct |
6 ms |
10896 KB |
Output is correct |