Submission #480824

# Submission time Handle Problem Language Result Execution time Memory
480824 2021-10-18T09:33:35 Z Rainbowbunny Semafor (COI20_semafor) C++17
100 / 100
285 ms 1356 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;

int Add(int x, int y)
{
    return x + y >= mod ? x + y - mod : x + y;
}

int Sub(int x, int y)
{
    return x - y < 0 ? x - y + mod : x - y;
}

int Mul(int x, int y)
{
    return 1ll * x * y % mod;
}

int BinPow(int n, long long k)
{
    int ans = 1, cur = n;
    while(k)
    {
        if(k & 1)
        {
            ans = Mul(ans, cur);
        }
        cur = Mul(cur, cur);
        k >>= 1;
    }
    return ans;
}

int fact[MAXN], ifact[MAXN];

int C(int k, int n)
{
    if(k > n or k < 0)
    {
        return 0;
    }
    return Mul(fact[n], Mul(ifact[k], ifact[n - k]));
}

void MulM(vector <vector <int> > &A, vector <vector <int> > B)
{
    int n = A.size();
    vector <vector <int> > C(n, vector <int> (n, 0));
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            for(int k = 0; k < n; k++)
            {
                C[i][j] = Add(C[i][j], Mul(A[i][k], B[k][j]));
            }
        }
    }
    swap(A, C);
}

void BinPowM(vector <vector <int> > &A, long long k)
{
    int n = A.size();
    vector <vector <int> > B(n, vector <int> (n));
    for(int i = 0; i < n; i++)
    {
        B[i][i] = 1;
    }
    while(k)
    {
        if(k & 1)
        {
            MulM(B, A);
        }
        MulM(A, A);
        k >>= 1;
    }
    swap(A, B);
}

int m, x;
int a[] = {10, 8, 18, 28, 9, 21, 6, 24, 23, 29};
long long n, k;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    fact[0] = 1;
    for(int i = 1; i < MAXN; i++)
    {
        fact[i] = Mul(fact[i - 1], i);
    }
    ifact[MAXN - 1] = BinPow(fact[MAXN - 1], mod - 2);
    for(int i = MAXN - 2; i >= 0; i--)
    {
        ifact[i] = Mul(ifact[i + 1], i + 1);
    }
    cin >> m >> n >> k >> x;
    if(m == 1)
    {
        vector <vector <int> > DP(6, vector <int> (6, 0));
        vector <vector <int> > Cnt(6, vector <int> (6, 0));
        DP[0][0] = 1;
        for(int i = 0; i < 6; i++)
        {
            if(i < 5)
            {
                Cnt[i][i + 1] = 5 - i;
            }
            if(i > 0)
            {
                Cnt[i][i - 1] = i;
            }
        }
        BinPowM(Cnt, k);
        MulM(DP, Cnt);
        for(int i = 0; i < 6; i++)
        {
            DP[0][i] = Mul(DP[0][i], BinPow(C(i, 5), mod - 2));
        }
        vector <vector <int> > Ans(10, vector <int> (10, 0));
        vector <vector <int> > NDP(10, vector <int> (10, 0));
        Ans[0][x] = 1;
        for(int i = 0; i < 10; i++)
        {
            for(int j = 0; j < 10; j++)
            {
                NDP[i][j] = DP[0][__builtin_popcount(a[i] ^ a[j])];
            }
        }
        BinPowM(NDP, n / k);
        MulM(Ans, NDP);
        n %= k;
        for(int i = 0; i < 6; i++)
        {
            for(int j = 0; j < 6; j++)
            {
                DP[i][j] = 0;
                Cnt[i][j] = 0;
            }
        }
        DP[0][0] = 1;
        for(int i = 0; i < 6; i++)
        {
            if(i < 5)
            {
                Cnt[i][i + 1] = 5 - i;
            }
            if(i > 0)
            {
                Cnt[i][i - 1] = i;
            }
        }
        BinPowM(Cnt, n);
        MulM(DP, Cnt);
        for(int i = 0; i < 6; i++)
        {
            DP[0][i] = Mul(DP[0][i], BinPow(C(i, 5), mod - 2));
        }
        for(int i = 0; i < 10; i++)
        {
            for(int j = 0; j < 10; j++)
            {
                NDP[i][j] = DP[0][__builtin_popcount(a[i] ^ a[j])];
            }
        }
        MulM(Ans, NDP);
        for(int i = 0; i < 10; i++)
        {
            cout << Ans[0][i] << '\n';
        }
    }
    else
    {
        vector <vector <int> > DP(11, vector <int> (11, 0));
        vector <vector <int> > Cnt(11, vector <int> (11, 0));
        DP[0][0] = 1;
        for(int i = 0; i < 11; i++)
        {
            if(i < 10)
            {
                Cnt[i][i + 1] = 10 - i;
            }
            if(i > 0)
            {
                Cnt[i][i - 1] = i;
            }
        }
        BinPowM(Cnt, k);
        MulM(DP, Cnt);
        for(int i = 0; i < 11; i++)
        {
            DP[0][i] = Mul(DP[0][i], BinPow(C(i, 10), mod - 2));
        }
        vector <vector <int> > Ans(100, vector <int> (100, 0));
        vector <vector <int> > NDP(100, vector <int> (100, 0));
        Ans[0][x] = 1;
        for(int i = 0; i < 100; i++)
        {
            for(int j = 0; j < 100; j++)
            {
                int t1 = i / 10, t2 = j / 10, t3 = i % 10, t4 = j % 10;
                NDP[i][j] = DP[0][__builtin_popcount(a[t1] ^ a[t2]) + __builtin_popcount(a[t3] ^ a[t4])];
            }
        }
        BinPowM(NDP, n / k);
        MulM(Ans, NDP);
        n %= k;
        for(int i = 0; i < 11; i++)
        {
            for(int j = 0; j < 11; j++)
            {
                DP[i][j] = 0;
                Cnt[i][j] = 0;
            }
        }
        DP[0][0] = 1;
        for(int i = 0; i < 11; i++)
        {
            if(i < 10)
            {
                Cnt[i][i + 1] = 10 - i;
            }
            if(i > 0)
            {
                Cnt[i][i - 1] = i;
            }
        }
        BinPowM(Cnt, n);
        MulM(DP, Cnt);
        for(int i = 0; i < 11; i++)
        {
            DP[0][i] = Mul(DP[0][i], BinPow(C(i, 10), mod - 2));
        }
        for(int i = 0; i < 100; i++)
        {
            for(int j = 0; j < 100; j++)
            {
                int t1 = i / 10, t2 = j / 10, t3 = i % 10, t4 = j % 10;
                NDP[i][j] = DP[0][__builtin_popcount(a[t1] ^ a[t2]) + __builtin_popcount(a[t3] ^ a[t4])];
            }
        }
        MulM(Ans, NDP);
        for(int i = 0; i < 100; i++)
        {
            cout << Ans[0][i] << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1068 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 3 ms 1100 KB Output is correct
4 Correct 3 ms 1100 KB Output is correct
5 Correct 3 ms 1096 KB Output is correct
6 Correct 2 ms 1100 KB Output is correct
7 Correct 2 ms 1100 KB Output is correct
8 Correct 2 ms 1100 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 2 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1068 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 3 ms 1100 KB Output is correct
4 Correct 3 ms 1100 KB Output is correct
5 Correct 3 ms 1096 KB Output is correct
6 Correct 2 ms 1100 KB Output is correct
7 Correct 2 ms 1100 KB Output is correct
8 Correct 2 ms 1100 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 2 ms 972 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 3 ms 1100 KB Output is correct
13 Correct 2 ms 1100 KB Output is correct
14 Correct 3 ms 1100 KB Output is correct
15 Correct 3 ms 1100 KB Output is correct
16 Correct 3 ms 1096 KB Output is correct
17 Correct 2 ms 1100 KB Output is correct
18 Correct 3 ms 1100 KB Output is correct
19 Correct 3 ms 1100 KB Output is correct
20 Correct 3 ms 1100 KB Output is correct
21 Correct 2 ms 1092 KB Output is correct
22 Correct 3 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1320 KB Output is correct
2 Correct 16 ms 1228 KB Output is correct
3 Correct 16 ms 1228 KB Output is correct
4 Correct 22 ms 1228 KB Output is correct
5 Correct 18 ms 1324 KB Output is correct
6 Correct 16 ms 1320 KB Output is correct
7 Correct 16 ms 1320 KB Output is correct
8 Correct 18 ms 1324 KB Output is correct
9 Correct 17 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 1228 KB Output is correct
2 Correct 152 ms 1228 KB Output is correct
3 Correct 203 ms 1300 KB Output is correct
4 Correct 285 ms 1300 KB Output is correct
5 Correct 253 ms 1228 KB Output is correct
6 Correct 258 ms 1308 KB Output is correct
7 Correct 255 ms 1348 KB Output is correct
8 Correct 246 ms 1356 KB Output is correct
9 Correct 241 ms 1308 KB Output is correct
10 Correct 244 ms 1228 KB Output is correct
11 Correct 36 ms 1324 KB Output is correct
12 Correct 19 ms 1320 KB Output is correct
13 Correct 270 ms 1300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 1228 KB Output is correct
2 Correct 152 ms 1228 KB Output is correct
3 Correct 203 ms 1300 KB Output is correct
4 Correct 285 ms 1300 KB Output is correct
5 Correct 253 ms 1228 KB Output is correct
6 Correct 258 ms 1308 KB Output is correct
7 Correct 255 ms 1348 KB Output is correct
8 Correct 246 ms 1356 KB Output is correct
9 Correct 241 ms 1308 KB Output is correct
10 Correct 244 ms 1228 KB Output is correct
11 Correct 36 ms 1324 KB Output is correct
12 Correct 19 ms 1320 KB Output is correct
13 Correct 270 ms 1300 KB Output is correct
14 Correct 33 ms 1228 KB Output is correct
15 Correct 109 ms 1300 KB Output is correct
16 Correct 164 ms 1296 KB Output is correct
17 Correct 209 ms 1304 KB Output is correct
18 Correct 250 ms 1228 KB Output is correct
19 Correct 189 ms 1348 KB Output is correct
20 Correct 231 ms 1232 KB Output is correct
21 Correct 249 ms 1300 KB Output is correct
22 Correct 243 ms 1348 KB Output is correct
23 Correct 200 ms 1304 KB Output is correct
24 Correct 215 ms 1228 KB Output is correct
25 Correct 219 ms 1300 KB Output is correct
26 Correct 22 ms 1228 KB Output is correct
27 Correct 29 ms 1244 KB Output is correct
28 Correct 160 ms 1348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1320 KB Output is correct
2 Correct 16 ms 1228 KB Output is correct
3 Correct 16 ms 1228 KB Output is correct
4 Correct 22 ms 1228 KB Output is correct
5 Correct 18 ms 1324 KB Output is correct
6 Correct 16 ms 1320 KB Output is correct
7 Correct 16 ms 1320 KB Output is correct
8 Correct 18 ms 1324 KB Output is correct
9 Correct 17 ms 1228 KB Output is correct
10 Correct 68 ms 1228 KB Output is correct
11 Correct 152 ms 1228 KB Output is correct
12 Correct 203 ms 1300 KB Output is correct
13 Correct 285 ms 1300 KB Output is correct
14 Correct 253 ms 1228 KB Output is correct
15 Correct 258 ms 1308 KB Output is correct
16 Correct 255 ms 1348 KB Output is correct
17 Correct 246 ms 1356 KB Output is correct
18 Correct 241 ms 1308 KB Output is correct
19 Correct 244 ms 1228 KB Output is correct
20 Correct 36 ms 1324 KB Output is correct
21 Correct 19 ms 1320 KB Output is correct
22 Correct 270 ms 1300 KB Output is correct
23 Correct 33 ms 1228 KB Output is correct
24 Correct 109 ms 1300 KB Output is correct
25 Correct 164 ms 1296 KB Output is correct
26 Correct 209 ms 1304 KB Output is correct
27 Correct 250 ms 1228 KB Output is correct
28 Correct 189 ms 1348 KB Output is correct
29 Correct 231 ms 1232 KB Output is correct
30 Correct 249 ms 1300 KB Output is correct
31 Correct 243 ms 1348 KB Output is correct
32 Correct 200 ms 1304 KB Output is correct
33 Correct 215 ms 1228 KB Output is correct
34 Correct 219 ms 1300 KB Output is correct
35 Correct 22 ms 1228 KB Output is correct
36 Correct 29 ms 1244 KB Output is correct
37 Correct 160 ms 1348 KB Output is correct
38 Correct 21 ms 1228 KB Output is correct
39 Correct 16 ms 1228 KB Output is correct
40 Correct 16 ms 1224 KB Output is correct
41 Correct 16 ms 1228 KB Output is correct
42 Correct 17 ms 1228 KB Output is correct
43 Correct 17 ms 1316 KB Output is correct
44 Correct 16 ms 1316 KB Output is correct
45 Correct 243 ms 1296 KB Output is correct
46 Correct 238 ms 1228 KB Output is correct
47 Correct 22 ms 1228 KB Output is correct
48 Correct 16 ms 1320 KB Output is correct
49 Correct 17 ms 1324 KB Output is correct
50 Correct 16 ms 1228 KB Output is correct
51 Correct 16 ms 1316 KB Output is correct
52 Correct 81 ms 1296 KB Output is correct