Submission #412054

# Submission time Handle Problem Language Result Execution time Memory
412054 2021-05-26T12:48:07 Z 최서현(#7464) Semafor (COI20_semafor) C++17
0 / 100
72 ms 716 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tiiii tuple<int, int, int, int>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
//#define DEBUG

using namespace std;

const int Q = (int)1e9 + 7;
const int X[10] = {3, 1, 18, 21, 9, 28, 6, 17, 30, 29};

vector<vector<int>> mul(const vector<vector<int>> &A, const vector<vector<int>> &B)
{
    int n = A.size();
    vector<vector<int>> C(n, vector<int>(n));
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
        for(int k = 0; k < n; ++k)
        C[i][k] = (C[i][k] + 1ll * A[i][j] * B[j][k] % Q) % Q;
    return C;
}

vector<vector<int>> pow(vector<vector<int>> A, long long x)
{
    int n = A.size();
    vector<vector<int>> R(n, vector<int>(n));
    for(int i = 0; i < n; ++i) R[i][i] = 1;
    while(x)
    {
        if(x & 1) R = mul(R, A);
        A = mul(A, A);
        x >>= 1;
    }
    return R;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int m, x; long long n, k; cin >> m >> n >> k >> x;

    vector<vector<int>> A(32, vector<int>(32));
    for(int i = 0; i < 32; ++i)
        for(int j = 0; j < 32; ++j)
            if(__builtin_popcount(i ^ j) == 1) A[i][j] = 1;

    #ifdef DEBUG
        cout << endl;
        cout << "A" << endl;
        for(auto i : A)
        {
            for(auto j : i) cout << j << ' ';
            cout << endl;
        }
        cout << endl;
    #endif

    vector<vector<int>> B[k + 1];
    B[0] = vector<vector<int>>(32, vector<int>(32, 0));
    for(int i = 0; i < 32; ++i) B[0][i][i] = 1;
    for(int i = 1; i <= k; ++i) B[i] = mul(B[i - 1], A);

    #ifdef DEBUG
        cout << endl;
        cout << "A" << endl;
        for(auto i : A)
        {
            for(auto j : i) cout << j << ' ';
            cout << endl;
        }
        cout << endl;
    #endif

    vector<vector<int>> D = vector<vector<int>>(100, vector<int>(100)), E = D;
    for(int i = 0; i < 100; ++i)
    {
        for(int j = 0; j < 100; ++j)
        {
            for(int l = 0; l <= k; ++l)
            {
                D[i][j] = (D[i][j] + 1ll * B[l][X[i / 10]][X[j / 10]] * B[k - l][X[i % 10]][X[j % 10]] % Q) % Q;
            }
        }
    }
    for(int i = 0; i < 100; ++i)
    {
        for(int j = 0; j < 100; ++j)
        {
            for(int l = 0; l <= n % k; ++l)
            {
                E[i][j] = (E[i][j] + 1ll * B[l][X[i / 10]][X[j / 10]] * B[n % k - l][X[i % 10]][X[j % 10]] % Q) % Q;
            }
        }
    }


    auto F = mul(pow(D, n / k), E);

    int ans = 0;
    for(int i = 0; i < 100; ++i) cout << F[x][i] << '\n';
}

Compilation message

semafor.cpp: In function 'int main()':
semafor.cpp:112:9: warning: unused variable 'ans' [-Wunused-variable]
  112 |     int ans = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 716 KB Output isn't correct
2 Halted 0 ms 0 KB -