Submission #412061

# Submission time Handle Problem Language Result Execution time Memory
412061 2021-05-26T13:01:29 Z 최서현(#7464) Semafor (COI20_semafor) C++17
39 / 100
2247 ms 524292 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 fact[101010];
int revf[101010];
int comb(int n, int r) { return 1ll * fact[n] * revf[r] % Q * revf[n - r] % Q; }

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

    fact[0] = 1; for(int i = 1; i < 101010; ++i) fact[i] = 1ll * fact[i - 1] * i % Q;
    revf[0] = revf[1] = 1; for(int i = 2; i < 101010; ++i) revf[i] = Q - 1ll * (Q / i) * revf[Q % i] % Q;
    for(int i = 1; i < 101010; ++i) revf[i] = 1ll * revf[i] * revf[i - 1] % Q;

    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 * comb(k, l) % 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 * comb(n % k, l) % 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:120:9: warning: unused variable 'ans' [-Wunused-variable]
  120 |     int ans = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 1228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 1228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1384 KB Output is correct
2 Correct 49 ms 1720 KB Output is correct
3 Correct 417 ms 6608 KB Output is correct
4 Correct 380 ms 7364 KB Output is correct
5 Correct 420 ms 7420 KB Output is correct
6 Correct 470 ms 8132 KB Output is correct
7 Correct 550 ms 9256 KB Output is correct
8 Correct 563 ms 9228 KB Output is correct
9 Correct 399 ms 7196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 1356 KB Output is correct
2 Correct 185 ms 1328 KB Output is correct
3 Correct 289 ms 1348 KB Output is correct
4 Correct 364 ms 1356 KB Output is correct
5 Correct 329 ms 1324 KB Output is correct
6 Correct 316 ms 1400 KB Output is correct
7 Correct 362 ms 1364 KB Output is correct
8 Correct 323 ms 1316 KB Output is correct
9 Correct 338 ms 1316 KB Output is correct
10 Correct 319 ms 1388 KB Output is correct
11 Correct 46 ms 1228 KB Output is correct
12 Correct 23 ms 1332 KB Output is correct
13 Correct 334 ms 1332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 1356 KB Output is correct
2 Correct 185 ms 1328 KB Output is correct
3 Correct 289 ms 1348 KB Output is correct
4 Correct 364 ms 1356 KB Output is correct
5 Correct 329 ms 1324 KB Output is correct
6 Correct 316 ms 1400 KB Output is correct
7 Correct 362 ms 1364 KB Output is correct
8 Correct 323 ms 1316 KB Output is correct
9 Correct 338 ms 1316 KB Output is correct
10 Correct 319 ms 1388 KB Output is correct
11 Correct 46 ms 1228 KB Output is correct
12 Correct 23 ms 1332 KB Output is correct
13 Correct 334 ms 1332 KB Output is correct
14 Correct 296 ms 5060 KB Output is correct
15 Correct 783 ms 8556 KB Output is correct
16 Correct 678 ms 7548 KB Output is correct
17 Correct 801 ms 8520 KB Output is correct
18 Correct 663 ms 5760 KB Output is correct
19 Correct 680 ms 5496 KB Output is correct
20 Correct 587 ms 5920 KB Output is correct
21 Correct 323 ms 1320 KB Output is correct
22 Correct 342 ms 1384 KB Output is correct
23 Correct 681 ms 6816 KB Output is correct
24 Correct 1226 ms 9232 KB Output is correct
25 Correct 999 ms 9256 KB Output is correct
26 Correct 30 ms 1232 KB Output is correct
27 Correct 46 ms 1368 KB Output is correct
28 Correct 948 ms 8936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1384 KB Output is correct
2 Correct 49 ms 1720 KB Output is correct
3 Correct 417 ms 6608 KB Output is correct
4 Correct 380 ms 7364 KB Output is correct
5 Correct 420 ms 7420 KB Output is correct
6 Correct 470 ms 8132 KB Output is correct
7 Correct 550 ms 9256 KB Output is correct
8 Correct 563 ms 9228 KB Output is correct
9 Correct 399 ms 7196 KB Output is correct
10 Correct 106 ms 1356 KB Output is correct
11 Correct 185 ms 1328 KB Output is correct
12 Correct 289 ms 1348 KB Output is correct
13 Correct 364 ms 1356 KB Output is correct
14 Correct 329 ms 1324 KB Output is correct
15 Correct 316 ms 1400 KB Output is correct
16 Correct 362 ms 1364 KB Output is correct
17 Correct 323 ms 1316 KB Output is correct
18 Correct 338 ms 1316 KB Output is correct
19 Correct 319 ms 1388 KB Output is correct
20 Correct 46 ms 1228 KB Output is correct
21 Correct 23 ms 1332 KB Output is correct
22 Correct 334 ms 1332 KB Output is correct
23 Correct 296 ms 5060 KB Output is correct
24 Correct 783 ms 8556 KB Output is correct
25 Correct 678 ms 7548 KB Output is correct
26 Correct 801 ms 8520 KB Output is correct
27 Correct 663 ms 5760 KB Output is correct
28 Correct 680 ms 5496 KB Output is correct
29 Correct 587 ms 5920 KB Output is correct
30 Correct 323 ms 1320 KB Output is correct
31 Correct 342 ms 1384 KB Output is correct
32 Correct 681 ms 6816 KB Output is correct
33 Correct 1226 ms 9232 KB Output is correct
34 Correct 999 ms 9256 KB Output is correct
35 Correct 30 ms 1232 KB Output is correct
36 Correct 46 ms 1368 KB Output is correct
37 Correct 948 ms 8936 KB Output is correct
38 Correct 2247 ms 20676 KB Output is correct
39 Runtime error 256 ms 524292 KB Execution killed with signal 9
40 Halted 0 ms 0 KB -