답안 #968027

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

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


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 main () {
    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];
    map <int,int> mp;
    // for (int i = 1; i <= n; i++) cout << find(i) << ' '; cout << '\n';
    // for (int i = 1; i <= n; i++) cout << ch[find(i)] << ' '; cout << '\n';
    for (int i = 1; i <= k; i++) {
        if (ch[find(i)] == 3) mp[find(i)]++;
        else if (ch[find(i)] == 1) {
            left--;
        }
    }

    dp[0] = 1;
    for (auto [x, y] : mp) {
        for (int i = left; i >= y; i--) add(dp[i], dp[i - y]);
    }
    cout << dp[left] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6488 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6488 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 1 ms 6560 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6488 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 1 ms 6560 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 115 ms 14932 KB Output is correct
36 Correct 129 ms 15932 KB Output is correct
37 Correct 140 ms 16084 KB Output is correct
38 Correct 136 ms 16408 KB Output is correct
39 Correct 117 ms 15708 KB Output is correct
40 Correct 140 ms 16216 KB Output is correct
41 Correct 135 ms 16212 KB Output is correct
42 Correct 116 ms 16016 KB Output is correct
43 Correct 114 ms 15644 KB Output is correct
44 Correct 119 ms 26708 KB Output is correct
45 Correct 115 ms 14928 KB Output is correct
46 Correct 124 ms 26664 KB Output is correct
47 Correct 117 ms 20816 KB Output is correct
48 Correct 138 ms 16224 KB Output is correct
49 Correct 135 ms 16204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6488 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 1 ms 6560 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 115 ms 14932 KB Output is correct
36 Correct 129 ms 15932 KB Output is correct
37 Correct 140 ms 16084 KB Output is correct
38 Correct 136 ms 16408 KB Output is correct
39 Correct 117 ms 15708 KB Output is correct
40 Correct 140 ms 16216 KB Output is correct
41 Correct 135 ms 16212 KB Output is correct
42 Correct 116 ms 16016 KB Output is correct
43 Correct 114 ms 15644 KB Output is correct
44 Correct 119 ms 26708 KB Output is correct
45 Correct 115 ms 14928 KB Output is correct
46 Correct 124 ms 26664 KB Output is correct
47 Correct 117 ms 20816 KB Output is correct
48 Correct 138 ms 16224 KB Output is correct
49 Correct 135 ms 16204 KB Output is correct
50 Correct 200 ms 16676 KB Output is correct
51 Correct 207 ms 16724 KB Output is correct
52 Correct 196 ms 16724 KB Output is correct
53 Correct 192 ms 16572 KB Output is correct
54 Correct 207 ms 16764 KB Output is correct
55 Correct 204 ms 16632 KB Output is correct
56 Correct 200 ms 16772 KB Output is correct
57 Correct 157 ms 16180 KB Output is correct
58 Correct 206 ms 16660 KB Output is correct
59 Correct 197 ms 16556 KB Output is correct
60 Correct 164 ms 16400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6488 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 2 ms 6492 KB Output is correct
29 Correct 1 ms 6560 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 115 ms 14932 KB Output is correct
36 Correct 129 ms 15932 KB Output is correct
37 Correct 140 ms 16084 KB Output is correct
38 Correct 136 ms 16408 KB Output is correct
39 Correct 117 ms 15708 KB Output is correct
40 Correct 140 ms 16216 KB Output is correct
41 Correct 135 ms 16212 KB Output is correct
42 Correct 116 ms 16016 KB Output is correct
43 Correct 114 ms 15644 KB Output is correct
44 Correct 119 ms 26708 KB Output is correct
45 Correct 115 ms 14928 KB Output is correct
46 Correct 124 ms 26664 KB Output is correct
47 Correct 117 ms 20816 KB Output is correct
48 Correct 138 ms 16224 KB Output is correct
49 Correct 135 ms 16204 KB Output is correct
50 Correct 200 ms 16676 KB Output is correct
51 Correct 207 ms 16724 KB Output is correct
52 Correct 196 ms 16724 KB Output is correct
53 Correct 192 ms 16572 KB Output is correct
54 Correct 207 ms 16764 KB Output is correct
55 Correct 204 ms 16632 KB Output is correct
56 Correct 200 ms 16772 KB Output is correct
57 Correct 157 ms 16180 KB Output is correct
58 Correct 206 ms 16660 KB Output is correct
59 Correct 197 ms 16556 KB Output is correct
60 Correct 164 ms 16400 KB Output is correct
61 Execution timed out 1055 ms 59472 KB Time limit exceeded
62 Halted 0 ms 0 KB -