답안 #968044

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968044 2024-04-23T07:18:41 Z weakweakweak Binaria (CCO23_day1problem1) C++17
25 / 25
211 ms 35428 KB
#include <bits/stdc++.h>
using namespace std;

const int M = 1000000 + 3, N = 1e6 + 10;
int a[N], ch[N], fa[N], dp[N] = {0}, fac[N], invfac[N];

int find (int x) {
    return fa[x] == x ? x : fa[x] = find (fa[x]);
}

void add (int &x, int y) {
    x += y;
    if (x >= M) x -= M;
    if (x < 0) x += M;
}

void merge (int i, int j) {
    i = find(i), j = find(j);
    if (i == j) return;
    fa[i] = j;
    if (ch[i] == 3 or ch[j] == 3) ch[j] = min(ch[i], ch[j]);
    else if (ch[i] != ch[j]) {
        cout << "0\n";
        exit(0);
    }
}

void f(int i, int val) {
    i = find(i);
    if (ch[i] == 3) ch[i] = val;
    else if (ch[i] != val) {
        cout << "0\n";
        exit(0);
    }
}

int fmul (int x, int t) {
    if (t == 0) return 1;
    long long y = fmul(x, t / 2);
    y = y * y % M;
    if (t & 1) y = y * x % M;
return y;}

int nCr (int x, int y) {
    return fac[x] * 1LL * invfac[y] % M * invfac[x - y] % M;
}

signed main () {

    fac[0] = 1;
    for (int i = 1; i <= 1000000; i++) fac[i] = fac[i - 1] * 1LL  * i % M;
    invfac[1000000] = fmul(fac[1000000], M - 2);
    for (int i = 999999; i >= 0; i--) invfac[i] = invfac[i + 1] * (i + 1LL) % M; 

    // cout << invfac[999999] * 1LL * fac[999999] % M<< '\n';
    // cout << fac[5] << ' ' << nCr(5, 3) << '\n';return 0;

    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) fa[i] = i, ch[i] = 3;
    for (int i = 1; i + k - 1 <= n; i++) cin >> a[i];
    for (int i = 2; i + k - 1 <= n; i++) {
        int dif = a[i] - a[i - 1];
        if (dif == 0) merge(i - 1, i + k - 1);
        else if (dif == 1) f(i + k - 1, 1), f(i - 1, 0);
        else f(i + k - 1, 0), f(i - 1, 1);
    }

    int left = a[1], wow = 0;
    for (int i = 1; i <= k; i++) {
        if (ch[find(i)] == 3) wow++;
        else if (ch[find(i)] == 1) {
            left--;
        }
    }

    cout << nCr (wow, left) << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14940 KB Output is correct
2 Correct 13 ms 14940 KB Output is correct
3 Correct 14 ms 14940 KB Output is correct
4 Correct 13 ms 14940 KB Output is correct
5 Correct 14 ms 14940 KB Output is correct
6 Correct 14 ms 14788 KB Output is correct
7 Correct 13 ms 14940 KB Output is correct
8 Correct 13 ms 14984 KB Output is correct
9 Correct 14 ms 14944 KB Output is correct
10 Correct 13 ms 14940 KB Output is correct
11 Correct 13 ms 14944 KB Output is correct
12 Correct 13 ms 15192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14940 KB Output is correct
2 Correct 13 ms 14940 KB Output is correct
3 Correct 14 ms 14940 KB Output is correct
4 Correct 13 ms 14940 KB Output is correct
5 Correct 14 ms 14940 KB Output is correct
6 Correct 14 ms 14788 KB Output is correct
7 Correct 13 ms 14940 KB Output is correct
8 Correct 13 ms 14984 KB Output is correct
9 Correct 14 ms 14944 KB Output is correct
10 Correct 13 ms 14940 KB Output is correct
11 Correct 13 ms 14944 KB Output is correct
12 Correct 13 ms 15192 KB Output is correct
13 Correct 14 ms 14936 KB Output is correct
14 Correct 14 ms 14976 KB Output is correct
15 Correct 14 ms 14940 KB Output is correct
16 Correct 14 ms 14928 KB Output is correct
17 Correct 13 ms 14944 KB Output is correct
18 Correct 13 ms 14936 KB Output is correct
19 Correct 13 ms 14968 KB Output is correct
20 Correct 13 ms 14948 KB Output is correct
21 Correct 13 ms 14944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14940 KB Output is correct
2 Correct 13 ms 14940 KB Output is correct
3 Correct 14 ms 14940 KB Output is correct
4 Correct 13 ms 14940 KB Output is correct
5 Correct 14 ms 14940 KB Output is correct
6 Correct 14 ms 14788 KB Output is correct
7 Correct 13 ms 14940 KB Output is correct
8 Correct 13 ms 14984 KB Output is correct
9 Correct 14 ms 14944 KB Output is correct
10 Correct 13 ms 14940 KB Output is correct
11 Correct 13 ms 14944 KB Output is correct
12 Correct 13 ms 15192 KB Output is correct
13 Correct 14 ms 14936 KB Output is correct
14 Correct 14 ms 14976 KB Output is correct
15 Correct 14 ms 14940 KB Output is correct
16 Correct 14 ms 14928 KB Output is correct
17 Correct 13 ms 14944 KB Output is correct
18 Correct 13 ms 14936 KB Output is correct
19 Correct 13 ms 14968 KB Output is correct
20 Correct 13 ms 14948 KB Output is correct
21 Correct 13 ms 14944 KB Output is correct
22 Correct 13 ms 14936 KB Output is correct
23 Correct 14 ms 14940 KB Output is correct
24 Correct 14 ms 14960 KB Output is correct
25 Correct 13 ms 14940 KB Output is correct
26 Correct 13 ms 14940 KB Output is correct
27 Correct 13 ms 15192 KB Output is correct
28 Correct 13 ms 14784 KB Output is correct
29 Correct 14 ms 14948 KB Output is correct
30 Correct 14 ms 15192 KB Output is correct
31 Correct 14 ms 14948 KB Output is correct
32 Correct 13 ms 14940 KB Output is correct
33 Correct 14 ms 14976 KB Output is correct
34 Correct 13 ms 14976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14940 KB Output is correct
2 Correct 13 ms 14940 KB Output is correct
3 Correct 14 ms 14940 KB Output is correct
4 Correct 13 ms 14940 KB Output is correct
5 Correct 14 ms 14940 KB Output is correct
6 Correct 14 ms 14788 KB Output is correct
7 Correct 13 ms 14940 KB Output is correct
8 Correct 13 ms 14984 KB Output is correct
9 Correct 14 ms 14944 KB Output is correct
10 Correct 13 ms 14940 KB Output is correct
11 Correct 13 ms 14944 KB Output is correct
12 Correct 13 ms 15192 KB Output is correct
13 Correct 14 ms 14936 KB Output is correct
14 Correct 14 ms 14976 KB Output is correct
15 Correct 14 ms 14940 KB Output is correct
16 Correct 14 ms 14928 KB Output is correct
17 Correct 13 ms 14944 KB Output is correct
18 Correct 13 ms 14936 KB Output is correct
19 Correct 13 ms 14968 KB Output is correct
20 Correct 13 ms 14948 KB Output is correct
21 Correct 13 ms 14944 KB Output is correct
22 Correct 13 ms 14936 KB Output is correct
23 Correct 14 ms 14940 KB Output is correct
24 Correct 14 ms 14960 KB Output is correct
25 Correct 13 ms 14940 KB Output is correct
26 Correct 13 ms 14940 KB Output is correct
27 Correct 13 ms 15192 KB Output is correct
28 Correct 13 ms 14784 KB Output is correct
29 Correct 14 ms 14948 KB Output is correct
30 Correct 14 ms 15192 KB Output is correct
31 Correct 14 ms 14948 KB Output is correct
32 Correct 13 ms 14940 KB Output is correct
33 Correct 14 ms 14976 KB Output is correct
34 Correct 13 ms 14976 KB Output is correct
35 Correct 128 ms 24148 KB Output is correct
36 Correct 143 ms 24916 KB Output is correct
37 Correct 147 ms 24900 KB Output is correct
38 Correct 161 ms 24912 KB Output is correct
39 Correct 133 ms 24144 KB Output is correct
40 Correct 149 ms 25092 KB Output is correct
41 Correct 155 ms 25160 KB Output is correct
42 Correct 124 ms 24552 KB Output is correct
43 Correct 129 ms 24308 KB Output is correct
44 Correct 134 ms 35428 KB Output is correct
45 Correct 130 ms 23668 KB Output is correct
46 Correct 143 ms 35416 KB Output is correct
47 Correct 148 ms 29536 KB Output is correct
48 Correct 154 ms 25220 KB Output is correct
49 Correct 148 ms 24884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14940 KB Output is correct
2 Correct 13 ms 14940 KB Output is correct
3 Correct 14 ms 14940 KB Output is correct
4 Correct 13 ms 14940 KB Output is correct
5 Correct 14 ms 14940 KB Output is correct
6 Correct 14 ms 14788 KB Output is correct
7 Correct 13 ms 14940 KB Output is correct
8 Correct 13 ms 14984 KB Output is correct
9 Correct 14 ms 14944 KB Output is correct
10 Correct 13 ms 14940 KB Output is correct
11 Correct 13 ms 14944 KB Output is correct
12 Correct 13 ms 15192 KB Output is correct
13 Correct 14 ms 14936 KB Output is correct
14 Correct 14 ms 14976 KB Output is correct
15 Correct 14 ms 14940 KB Output is correct
16 Correct 14 ms 14928 KB Output is correct
17 Correct 13 ms 14944 KB Output is correct
18 Correct 13 ms 14936 KB Output is correct
19 Correct 13 ms 14968 KB Output is correct
20 Correct 13 ms 14948 KB Output is correct
21 Correct 13 ms 14944 KB Output is correct
22 Correct 13 ms 14936 KB Output is correct
23 Correct 14 ms 14940 KB Output is correct
24 Correct 14 ms 14960 KB Output is correct
25 Correct 13 ms 14940 KB Output is correct
26 Correct 13 ms 14940 KB Output is correct
27 Correct 13 ms 15192 KB Output is correct
28 Correct 13 ms 14784 KB Output is correct
29 Correct 14 ms 14948 KB Output is correct
30 Correct 14 ms 15192 KB Output is correct
31 Correct 14 ms 14948 KB Output is correct
32 Correct 13 ms 14940 KB Output is correct
33 Correct 14 ms 14976 KB Output is correct
34 Correct 13 ms 14976 KB Output is correct
35 Correct 128 ms 24148 KB Output is correct
36 Correct 143 ms 24916 KB Output is correct
37 Correct 147 ms 24900 KB Output is correct
38 Correct 161 ms 24912 KB Output is correct
39 Correct 133 ms 24144 KB Output is correct
40 Correct 149 ms 25092 KB Output is correct
41 Correct 155 ms 25160 KB Output is correct
42 Correct 124 ms 24552 KB Output is correct
43 Correct 129 ms 24308 KB Output is correct
44 Correct 134 ms 35428 KB Output is correct
45 Correct 130 ms 23668 KB Output is correct
46 Correct 143 ms 35416 KB Output is correct
47 Correct 148 ms 29536 KB Output is correct
48 Correct 154 ms 25220 KB Output is correct
49 Correct 148 ms 24884 KB Output is correct
50 Correct 198 ms 25988 KB Output is correct
51 Correct 208 ms 26184 KB Output is correct
52 Correct 211 ms 26060 KB Output is correct
53 Correct 199 ms 26092 KB Output is correct
54 Correct 202 ms 26056 KB Output is correct
55 Correct 197 ms 26196 KB Output is correct
56 Correct 205 ms 25936 KB Output is correct
57 Correct 173 ms 25296 KB Output is correct
58 Correct 200 ms 26128 KB Output is correct
59 Correct 199 ms 25940 KB Output is correct
60 Correct 171 ms 25272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14940 KB Output is correct
2 Correct 13 ms 14940 KB Output is correct
3 Correct 14 ms 14940 KB Output is correct
4 Correct 13 ms 14940 KB Output is correct
5 Correct 14 ms 14940 KB Output is correct
6 Correct 14 ms 14788 KB Output is correct
7 Correct 13 ms 14940 KB Output is correct
8 Correct 13 ms 14984 KB Output is correct
9 Correct 14 ms 14944 KB Output is correct
10 Correct 13 ms 14940 KB Output is correct
11 Correct 13 ms 14944 KB Output is correct
12 Correct 13 ms 15192 KB Output is correct
13 Correct 14 ms 14936 KB Output is correct
14 Correct 14 ms 14976 KB Output is correct
15 Correct 14 ms 14940 KB Output is correct
16 Correct 14 ms 14928 KB Output is correct
17 Correct 13 ms 14944 KB Output is correct
18 Correct 13 ms 14936 KB Output is correct
19 Correct 13 ms 14968 KB Output is correct
20 Correct 13 ms 14948 KB Output is correct
21 Correct 13 ms 14944 KB Output is correct
22 Correct 13 ms 14936 KB Output is correct
23 Correct 14 ms 14940 KB Output is correct
24 Correct 14 ms 14960 KB Output is correct
25 Correct 13 ms 14940 KB Output is correct
26 Correct 13 ms 14940 KB Output is correct
27 Correct 13 ms 15192 KB Output is correct
28 Correct 13 ms 14784 KB Output is correct
29 Correct 14 ms 14948 KB Output is correct
30 Correct 14 ms 15192 KB Output is correct
31 Correct 14 ms 14948 KB Output is correct
32 Correct 13 ms 14940 KB Output is correct
33 Correct 14 ms 14976 KB Output is correct
34 Correct 13 ms 14976 KB Output is correct
35 Correct 128 ms 24148 KB Output is correct
36 Correct 143 ms 24916 KB Output is correct
37 Correct 147 ms 24900 KB Output is correct
38 Correct 161 ms 24912 KB Output is correct
39 Correct 133 ms 24144 KB Output is correct
40 Correct 149 ms 25092 KB Output is correct
41 Correct 155 ms 25160 KB Output is correct
42 Correct 124 ms 24552 KB Output is correct
43 Correct 129 ms 24308 KB Output is correct
44 Correct 134 ms 35428 KB Output is correct
45 Correct 130 ms 23668 KB Output is correct
46 Correct 143 ms 35416 KB Output is correct
47 Correct 148 ms 29536 KB Output is correct
48 Correct 154 ms 25220 KB Output is correct
49 Correct 148 ms 24884 KB Output is correct
50 Correct 198 ms 25988 KB Output is correct
51 Correct 208 ms 26184 KB Output is correct
52 Correct 211 ms 26060 KB Output is correct
53 Correct 199 ms 26092 KB Output is correct
54 Correct 202 ms 26056 KB Output is correct
55 Correct 197 ms 26196 KB Output is correct
56 Correct 205 ms 25936 KB Output is correct
57 Correct 173 ms 25296 KB Output is correct
58 Correct 200 ms 26128 KB Output is correct
59 Correct 199 ms 25940 KB Output is correct
60 Correct 171 ms 25272 KB Output is correct
61 Correct 15 ms 19036 KB Output is correct
62 Correct 16 ms 19036 KB Output is correct
63 Correct 16 ms 19032 KB Output is correct
64 Correct 16 ms 19036 KB Output is correct
65 Correct 125 ms 24424 KB Output is correct
66 Correct 93 ms 23268 KB Output is correct
67 Correct 201 ms 26252 KB Output is correct
68 Correct 32 ms 19292 KB Output is correct
69 Correct 16 ms 19036 KB Output is correct
70 Correct 16 ms 18868 KB Output is correct
71 Correct 15 ms 18880 KB Output is correct