답안 #968067

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968067 2024-04-23T07:31:18 Z becaido Binaria (CCO23_day1problem1) C++17
25 / 25
87 ms 20192 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

const int MOD = 1e6 + 3;
const int SIZE = 1e6 + 5;

int n, k;
int a[SIZE];

int pro[SIZE], inv[SIZE];
int power(int d, int up) {
    int re = 1;
    while (up) {
        if (up & 1) re = 1ll * re * d % MOD;
        d = 1ll * d * d % MOD;
        up >>= 1;
    }
    return re;
}
int C(int x, int y) {
    return 1ll * pro[x] * inv[y] % MOD * inv[x - y] % MOD;
}

int to[SIZE], ty[SIZE];
int dsu(int x) {
    return x == to[x] ? x : (to[x] = dsu(to[x]));
}
void merge(int a, int b) {
    a = dsu(a), b = dsu(b);
    if (a == b) return;
    to[b] = a;
    ty[a] |= ty[b];
}

void solve() {
    cin >> n >> k;
    FOR (i, k, n) cin >> a[i];
    iota(to + 1, to + n + 1, 1);

    pro[0] = 1;
    FOR (i, 1, n) pro[i] = 1ll * pro[i - 1] * i % MOD;
    inv[n] = power(pro[n], MOD - 2);
    for (int i = n; i >= 1; i--) inv[i - 1] = 1ll * inv[i] * i % MOD;

    FOR (i, k, n - 1) {
        if (a[i] == a[i + 1]) merge(i - k + 1, i + 1);
        if (a[i] + 1 == a[i + 1]) {
            ty[dsu(i - k + 1)] = 1;
            ty[dsu(i + 1)] = 2;
        }
        if (a[i] - 1 == a[i + 1]) {
            ty[dsu(i - k + 1)] = 2;
            ty[dsu(i + 1)] = 1;
        }
    }

    int c[3] = {};
    FOR (i, 1, k) c[ty[dsu(i)]]++;
    cout << C(c[0], a[k] - c[2]) << '\n';
}

int main() {
    Waimai;
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8660 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8696 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8660 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8696 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8660 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8696 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 2 ms 8536 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8536 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
34 Correct 1 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8660 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8696 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 2 ms 8536 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8536 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
34 Correct 1 ms 8540 KB Output is correct
35 Correct 55 ms 17616 KB Output is correct
36 Correct 66 ms 20192 KB Output is correct
37 Correct 60 ms 19808 KB Output is correct
38 Correct 59 ms 19828 KB Output is correct
39 Correct 53 ms 17748 KB Output is correct
40 Correct 56 ms 17748 KB Output is correct
41 Correct 61 ms 19960 KB Output is correct
42 Correct 55 ms 20000 KB Output is correct
43 Correct 55 ms 19928 KB Output is correct
44 Correct 54 ms 17612 KB Output is correct
45 Correct 53 ms 17748 KB Output is correct
46 Correct 53 ms 17744 KB Output is correct
47 Correct 59 ms 17608 KB Output is correct
48 Correct 77 ms 17608 KB Output is correct
49 Correct 57 ms 17612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8660 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8696 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 2 ms 8536 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8536 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
34 Correct 1 ms 8540 KB Output is correct
35 Correct 55 ms 17616 KB Output is correct
36 Correct 66 ms 20192 KB Output is correct
37 Correct 60 ms 19808 KB Output is correct
38 Correct 59 ms 19828 KB Output is correct
39 Correct 53 ms 17748 KB Output is correct
40 Correct 56 ms 17748 KB Output is correct
41 Correct 61 ms 19960 KB Output is correct
42 Correct 55 ms 20000 KB Output is correct
43 Correct 55 ms 19928 KB Output is correct
44 Correct 54 ms 17612 KB Output is correct
45 Correct 53 ms 17748 KB Output is correct
46 Correct 53 ms 17744 KB Output is correct
47 Correct 59 ms 17608 KB Output is correct
48 Correct 77 ms 17608 KB Output is correct
49 Correct 57 ms 17612 KB Output is correct
50 Correct 69 ms 17744 KB Output is correct
51 Correct 76 ms 17596 KB Output is correct
52 Correct 70 ms 19796 KB Output is correct
53 Correct 75 ms 19796 KB Output is correct
54 Correct 87 ms 19792 KB Output is correct
55 Correct 67 ms 19284 KB Output is correct
56 Correct 68 ms 19792 KB Output is correct
57 Correct 64 ms 19792 KB Output is correct
58 Correct 67 ms 17796 KB Output is correct
59 Correct 69 ms 19832 KB Output is correct
60 Correct 69 ms 19820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8660 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8696 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8536 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 2 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 1 ms 8540 KB Output is correct
28 Correct 2 ms 8536 KB Output is correct
29 Correct 1 ms 8540 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 1 ms 8540 KB Output is correct
32 Correct 1 ms 8536 KB Output is correct
33 Correct 1 ms 8540 KB Output is correct
34 Correct 1 ms 8540 KB Output is correct
35 Correct 55 ms 17616 KB Output is correct
36 Correct 66 ms 20192 KB Output is correct
37 Correct 60 ms 19808 KB Output is correct
38 Correct 59 ms 19828 KB Output is correct
39 Correct 53 ms 17748 KB Output is correct
40 Correct 56 ms 17748 KB Output is correct
41 Correct 61 ms 19960 KB Output is correct
42 Correct 55 ms 20000 KB Output is correct
43 Correct 55 ms 19928 KB Output is correct
44 Correct 54 ms 17612 KB Output is correct
45 Correct 53 ms 17748 KB Output is correct
46 Correct 53 ms 17744 KB Output is correct
47 Correct 59 ms 17608 KB Output is correct
48 Correct 77 ms 17608 KB Output is correct
49 Correct 57 ms 17612 KB Output is correct
50 Correct 69 ms 17744 KB Output is correct
51 Correct 76 ms 17596 KB Output is correct
52 Correct 70 ms 19796 KB Output is correct
53 Correct 75 ms 19796 KB Output is correct
54 Correct 87 ms 19792 KB Output is correct
55 Correct 67 ms 19284 KB Output is correct
56 Correct 68 ms 19792 KB Output is correct
57 Correct 64 ms 19792 KB Output is correct
58 Correct 67 ms 17796 KB Output is correct
59 Correct 69 ms 19832 KB Output is correct
60 Correct 69 ms 19820 KB Output is correct
61 Correct 14 ms 14680 KB Output is correct
62 Correct 14 ms 14684 KB Output is correct
63 Correct 14 ms 14684 KB Output is correct
64 Correct 14 ms 14812 KB Output is correct
65 Correct 46 ms 19796 KB Output is correct
66 Correct 37 ms 19792 KB Output is correct
67 Correct 71 ms 19944 KB Output is correct
68 Correct 22 ms 15452 KB Output is correct
69 Correct 15 ms 14684 KB Output is correct
70 Correct 14 ms 14680 KB Output is correct
71 Correct 14 ms 14684 KB Output is correct