# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
584020 | eecs | Semafor (COI20_semafor) | C++17 | 8 ms | 436 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 qp = [](auto A, ll k) {
decltype(A) B{};
for (int i = 0; i < A.size(); i++) {
B[i][i] = 1;
}
for (; k; k >>= 1, A = mul(A, A)) {
if (k & 1) B = mul(B, A);
}
return B;
};
int main() {
cin >> m >> n >> K >> X;
if (m == 1) {
typedef array<array<int, 32>, 32> mat1;
mat1 nxt{};
for (int i = 0; i < 32; i++) {
for (int j = 0; j < 5; j++) {
nxt[i][i ^ (1 << j)]++;
}
}
typedef array<array<int, 10>, 10> mat2;
auto A = qp(nxt, K);
mat2 tr;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
tr[i][j] = A[mask[i]][mask[j]];
}
}
mat2 res{};
res[0][X] = 1, res = mul(res, qp(tr, n / K));
A = qp(nxt, 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);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |