Submission #584028

# Submission time Handle Problem Language Result Execution time Memory
584028 2022-06-26T16:49:16 Z eecs Semafor (COI20_semafor) C++17
100 / 100
410 ms 4696 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int P = 1000000007, mask[] = {10, 2, 9, 7, 18, 21, 12, 3, 29, 23};
int m, X;
ll n, K;

auto mul = [](auto A, auto B) {
    int n = A.size();
    decltype(A) C{};
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) if (A[i][j]) {
            for (int k = 0; k < n; k++) {
                C[i][k] = (C[i][k] + 1LL * A[i][j] * B[j][k]) % P;
            }
        }
    }
    return C;
};

auto conv = [](auto A, auto B) {
    int n = A.size();
    decltype(A) C{};
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            C[i ^ j] = (C[i ^ j] + 1LL * A[i] * B[j]) % P;
        }
    }
    return C;
};

auto qp = [](auto A, ll k, auto op) {
    auto B = A;
    for (k--; k; k >>= 1, A = op(A, A)) {
        if (k & 1) B = op(B, A);
    }
    return B;
};

int main() {
    cin >> m >> n >> K >> X;
    if (m == 1) {
        auto get = [&](ll k) {
            typedef array<int, 32> arr;
            arr A{};
            for (int i = 0; i < 5; i++) {
                A[1 << i] = 1;
            }
            A = qp(A, k, conv);
            array<array<int, 32>, 32> res{};
            for (int i = 0; i < 32; i++) {
                for (int j = 0; j < 32; j++) {
                    res[i][j] = A[i ^ j];
                }
            }
            return res;
        };
        typedef array<array<int, 10>, 10> mat;
        auto A = get(K);
        mat tr;
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                tr[i][j] = A[mask[i]][mask[j]];
            }
        }
        mat res{};
        res[0][X] = 1, res = mul(res, qp(tr, n / K, mul));
        if (n % K) {
            A = get(n % K);
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    tr[i][j] = A[mask[i]][mask[j]];
                }
            }
            res = mul(res, tr);
        }
        for (int i = 0; i < 10; i++) {
            cout << res[0][i] << "\n";
        }
        exit(0);
    }
    auto get = [&](ll k) {
        typedef array<int, 1024> arr;
        arr A{};
        for (int i = 0; i < 10; i++) {
            A[1 << i] = 1;
        }
        A = qp(A, k, conv);
        array<array<int, 1024>, 1024> res{};
        for (int i = 0; i < 1024; i++) {
            for (int j = 0; j < 1024; j++) {
                res[i][j] = A[i ^ j];
            }
        }
        return res;
    };
    typedef array<array<int, 100>, 100> mat;
    auto A = get(K);
    mat tr;
    for (int i = 0; i < 100; i++) {
        int x = mask[i / 10] << 5 | mask[i % 10];
        for (int j = 0; j < 100; j++) {
            int y = mask[j / 10] << 5 | mask[j % 10];
            tr[i][j] = A[x][y];
        }
    }
    mat res{};
    res[0][X] = 1, res = mul(res, qp(tr, n / K, mul));
    if (n % K) {
        A = get(n % K);
        for (int i = 0; i < 100; i++) {
            int x = mask[i / 10] << 5 | mask[i % 10];
            for (int j = 0; j < 100; j++) {
                int y = mask[j / 10] << 5 | mask[j % 10];
                tr[i][j] = A[x][y];
            }
        }
        res = mul(res, tr);
    }
    for (int i = 0; i < 100; i++) {
        cout << res[0][i] << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4564 KB Output is correct
2 Correct 2 ms 4616 KB Output is correct
3 Correct 2 ms 4564 KB Output is correct
4 Correct 2 ms 4564 KB Output is correct
5 Correct 2 ms 4564 KB Output is correct
6 Correct 2 ms 4564 KB Output is correct
7 Correct 2 ms 4564 KB Output is correct
8 Correct 2 ms 4564 KB Output is correct
9 Correct 2 ms 4564 KB Output is correct
10 Correct 2 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4564 KB Output is correct
2 Correct 2 ms 4616 KB Output is correct
3 Correct 2 ms 4564 KB Output is correct
4 Correct 2 ms 4564 KB Output is correct
5 Correct 2 ms 4564 KB Output is correct
6 Correct 2 ms 4564 KB Output is correct
7 Correct 2 ms 4564 KB Output is correct
8 Correct 2 ms 4564 KB Output is correct
9 Correct 2 ms 4564 KB Output is correct
10 Correct 2 ms 4564 KB Output is correct
11 Correct 2 ms 4564 KB Output is correct
12 Correct 2 ms 4564 KB Output is correct
13 Correct 2 ms 4564 KB Output is correct
14 Correct 3 ms 4564 KB Output is correct
15 Correct 3 ms 4564 KB Output is correct
16 Correct 2 ms 4564 KB Output is correct
17 Correct 3 ms 4564 KB Output is correct
18 Correct 2 ms 4564 KB Output is correct
19 Correct 2 ms 4564 KB Output is correct
20 Correct 3 ms 4564 KB Output is correct
21 Correct 2 ms 4564 KB Output is correct
22 Correct 3 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4688 KB Output is correct
2 Correct 31 ms 4668 KB Output is correct
3 Correct 48 ms 4692 KB Output is correct
4 Correct 46 ms 4672 KB Output is correct
5 Correct 39 ms 4672 KB Output is correct
6 Correct 44 ms 4692 KB Output is correct
7 Correct 52 ms 4692 KB Output is correct
8 Correct 49 ms 4672 KB Output is correct
9 Correct 58 ms 4692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 4564 KB Output is correct
2 Correct 54 ms 4564 KB Output is correct
3 Correct 72 ms 4692 KB Output is correct
4 Correct 122 ms 4672 KB Output is correct
5 Correct 83 ms 4676 KB Output is correct
6 Correct 116 ms 4692 KB Output is correct
7 Correct 105 ms 4672 KB Output is correct
8 Correct 47 ms 4692 KB Output is correct
9 Correct 48 ms 4692 KB Output is correct
10 Correct 107 ms 4684 KB Output is correct
11 Correct 5 ms 4692 KB Output is correct
12 Correct 4 ms 4672 KB Output is correct
13 Correct 117 ms 4692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 4564 KB Output is correct
2 Correct 54 ms 4564 KB Output is correct
3 Correct 72 ms 4692 KB Output is correct
4 Correct 122 ms 4672 KB Output is correct
5 Correct 83 ms 4676 KB Output is correct
6 Correct 116 ms 4692 KB Output is correct
7 Correct 105 ms 4672 KB Output is correct
8 Correct 47 ms 4692 KB Output is correct
9 Correct 48 ms 4692 KB Output is correct
10 Correct 107 ms 4684 KB Output is correct
11 Correct 5 ms 4692 KB Output is correct
12 Correct 4 ms 4672 KB Output is correct
13 Correct 117 ms 4692 KB Output is correct
14 Correct 76 ms 4692 KB Output is correct
15 Correct 139 ms 4692 KB Output is correct
16 Correct 128 ms 4676 KB Output is correct
17 Correct 144 ms 4692 KB Output is correct
18 Correct 145 ms 4684 KB Output is correct
19 Correct 138 ms 4692 KB Output is correct
20 Correct 158 ms 4672 KB Output is correct
21 Correct 41 ms 4564 KB Output is correct
22 Correct 135 ms 4676 KB Output is correct
23 Correct 147 ms 4692 KB Output is correct
24 Correct 162 ms 4564 KB Output is correct
25 Correct 156 ms 4692 KB Output is correct
26 Correct 13 ms 4696 KB Output is correct
27 Correct 25 ms 4692 KB Output is correct
28 Correct 144 ms 4692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4688 KB Output is correct
2 Correct 31 ms 4668 KB Output is correct
3 Correct 48 ms 4692 KB Output is correct
4 Correct 46 ms 4672 KB Output is correct
5 Correct 39 ms 4672 KB Output is correct
6 Correct 44 ms 4692 KB Output is correct
7 Correct 52 ms 4692 KB Output is correct
8 Correct 49 ms 4672 KB Output is correct
9 Correct 58 ms 4692 KB Output is correct
10 Correct 47 ms 4564 KB Output is correct
11 Correct 54 ms 4564 KB Output is correct
12 Correct 72 ms 4692 KB Output is correct
13 Correct 122 ms 4672 KB Output is correct
14 Correct 83 ms 4676 KB Output is correct
15 Correct 116 ms 4692 KB Output is correct
16 Correct 105 ms 4672 KB Output is correct
17 Correct 47 ms 4692 KB Output is correct
18 Correct 48 ms 4692 KB Output is correct
19 Correct 107 ms 4684 KB Output is correct
20 Correct 5 ms 4692 KB Output is correct
21 Correct 4 ms 4672 KB Output is correct
22 Correct 117 ms 4692 KB Output is correct
23 Correct 76 ms 4692 KB Output is correct
24 Correct 139 ms 4692 KB Output is correct
25 Correct 128 ms 4676 KB Output is correct
26 Correct 144 ms 4692 KB Output is correct
27 Correct 145 ms 4684 KB Output is correct
28 Correct 138 ms 4692 KB Output is correct
29 Correct 158 ms 4672 KB Output is correct
30 Correct 41 ms 4564 KB Output is correct
31 Correct 135 ms 4676 KB Output is correct
32 Correct 147 ms 4692 KB Output is correct
33 Correct 162 ms 4564 KB Output is correct
34 Correct 156 ms 4692 KB Output is correct
35 Correct 13 ms 4696 KB Output is correct
36 Correct 25 ms 4692 KB Output is correct
37 Correct 144 ms 4692 KB Output is correct
38 Correct 91 ms 4692 KB Output is correct
39 Correct 218 ms 4672 KB Output is correct
40 Correct 294 ms 4676 KB Output is correct
41 Correct 410 ms 4672 KB Output is correct
42 Correct 381 ms 4684 KB Output is correct
43 Correct 389 ms 4692 KB Output is correct
44 Correct 391 ms 4692 KB Output is correct
45 Correct 46 ms 4672 KB Output is correct
46 Correct 109 ms 4692 KB Output is correct
47 Correct 379 ms 4692 KB Output is correct
48 Correct 216 ms 4692 KB Output is correct
49 Correct 207 ms 4692 KB Output is correct
50 Correct 20 ms 4692 KB Output is correct
51 Correct 51 ms 4680 KB Output is correct
52 Correct 309 ms 4692 KB Output is correct