Submission #593197

# Submission time Handle Problem Language Result Execution time Memory
593197 2022-07-10T14:51:42 Z jiahng Semafor (COI20_semafor) C++14
100 / 100
308 ms 1108 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
typedef pair<int,ll> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 200100
#define INF (ll)1e14
#define MOD 1000000007
#define getchar_unlocked _getchar_nolock


int M,N,K,X;
int numbers[10] = {0b01010, 0b01000, 0b10010,0b11100,0b01001,0b10101,0b00110, 0b11000, 0b10111, 0b11101};

struct Matrix{
    int mat[100][100];
    int N;
    Matrix(int _N){
        N = _N;
        FOR(i,0,N-1) FOR(j,0,N-1) mat[i][j] = 0;
    }
    Matrix operator*(Matrix mat2){
        Matrix new_mat = Matrix(N);
        FOR(i,0,N-1) FOR(j,0,N-1) FOR(k,0,N-1) (new_mat.mat[i][j] += (mat[i][k] * mat2.mat[k][j]) % MOD) %= MOD;
        return new_mat;
    }
    void print(){
        FOR(i,0,N-1){
            FOR(j,0,N-1) cout << mat[i][j] << ' ';
            cout << '\n';
        }
    }
};
Matrix qexp(Matrix mat, int b){
    Matrix ans = Matrix(mat.N);
    FOR(i,0,mat.N-1) ans.mat[i][i] = 1;
    while (b){
        if (b&1) ans = mat * ans;
        mat = mat * mat;
        b >>= 1;
    }
    return ans;
}
int32_t main(){
    fast;
    cin >> M >> N >> K >> X;
    
    Matrix mat1 = Matrix(5*M+1);
    FOR(i,0,5*M){
        if (i > 0) mat1.mat[i][i-1] = i;
        if (i < 5*M) mat1.mat[i][i+1] = 5*M-i;
    }
    //mat1.print(5*M);
    //cout << '\n';
    Matrix mat2 = qexp(mat1, K);
    //mat2.print();
    if (M == 1){    
        Matrix adj = Matrix(10);
        FOR(i,0,9) FOR(j,0,9){
            adj.mat[i][j] = mat2.mat[__builtin_popcount(numbers[i] ^ numbers[j])][0];
        }

        adj = qexp(adj, N/K);
        // N%K operations left

        Matrix mat3 = qexp(mat1, N%K);
        FOR(i,0,9){ //final state
            int ans = 0;
            FOR(j,0,9){ // intermediate state
                int numdiff = __builtin_popcount(numbers[j] ^ numbers[i]);
                (ans += (mat3.mat[numdiff][0] * adj.mat[X][j]) % MOD) %= MOD;
            }
            cout << ans << '\n';
        }
    }else{
        Matrix adj = Matrix(100);
        FOR(i,0,9) FOR(i2,0,9) FOR(j,0,9) FOR(j2,0,9){
            adj.mat[i+10*i2][j+10*j2] = mat2.mat[__builtin_popcount(numbers[i] ^ numbers[j]) + __builtin_popcount(numbers[i2] ^ numbers[j2])][0];
        }
        adj = qexp(adj, N / K);

        Matrix mat3 = qexp(mat1, N%K);
        FOR(i,0,9) FOR(i2,0,9){ // final state
            int ans = 0;
            FOR(j,0,9) FOR(j2,0,9){ // intermediate state
                int numdiff = __builtin_popcount(numbers[i] ^ numbers[j]) + __builtin_popcount(numbers[i2] ^ numbers[j2]);
                (ans += (mat3.mat[numdiff][0] * adj.mat[X][10*j+j2]) % MOD) %= MOD;
            }
            cout << ans << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1104 KB Output is correct
4 Correct 1 ms 1088 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1096 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1104 KB Output is correct
4 Correct 1 ms 1088 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1096 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 992 KB Output is correct
12 Correct 1 ms 1092 KB Output is correct
13 Correct 2 ms 1092 KB Output is correct
14 Correct 2 ms 1096 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 2 ms 1096 KB Output is correct
17 Correct 2 ms 1096 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 2 ms 980 KB Output is correct
21 Correct 2 ms 980 KB Output is correct
22 Correct 2 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 980 KB Output is correct
2 Correct 9 ms 1104 KB Output is correct
3 Correct 11 ms 1104 KB Output is correct
4 Correct 11 ms 980 KB Output is correct
5 Correct 11 ms 1100 KB Output is correct
6 Correct 11 ms 980 KB Output is correct
7 Correct 10 ms 1104 KB Output is correct
8 Correct 10 ms 1104 KB Output is correct
9 Correct 13 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 1080 KB Output is correct
2 Correct 167 ms 1076 KB Output is correct
3 Correct 237 ms 1084 KB Output is correct
4 Correct 304 ms 1084 KB Output is correct
5 Correct 292 ms 1084 KB Output is correct
6 Correct 282 ms 980 KB Output is correct
7 Correct 308 ms 1076 KB Output is correct
8 Correct 289 ms 980 KB Output is correct
9 Correct 277 ms 1100 KB Output is correct
10 Correct 284 ms 1100 KB Output is correct
11 Correct 34 ms 1092 KB Output is correct
12 Correct 15 ms 1108 KB Output is correct
13 Correct 300 ms 1096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 1080 KB Output is correct
2 Correct 167 ms 1076 KB Output is correct
3 Correct 237 ms 1084 KB Output is correct
4 Correct 304 ms 1084 KB Output is correct
5 Correct 292 ms 1084 KB Output is correct
6 Correct 282 ms 980 KB Output is correct
7 Correct 308 ms 1076 KB Output is correct
8 Correct 289 ms 980 KB Output is correct
9 Correct 277 ms 1100 KB Output is correct
10 Correct 284 ms 1100 KB Output is correct
11 Correct 34 ms 1092 KB Output is correct
12 Correct 15 ms 1108 KB Output is correct
13 Correct 300 ms 1096 KB Output is correct
14 Correct 32 ms 980 KB Output is correct
15 Correct 119 ms 1088 KB Output is correct
16 Correct 169 ms 980 KB Output is correct
17 Correct 231 ms 1080 KB Output is correct
18 Correct 259 ms 1076 KB Output is correct
19 Correct 225 ms 1084 KB Output is correct
20 Correct 249 ms 1096 KB Output is correct
21 Correct 278 ms 1076 KB Output is correct
22 Correct 286 ms 1096 KB Output is correct
23 Correct 230 ms 1084 KB Output is correct
24 Correct 240 ms 980 KB Output is correct
25 Correct 239 ms 1096 KB Output is correct
26 Correct 17 ms 1100 KB Output is correct
27 Correct 24 ms 980 KB Output is correct
28 Correct 180 ms 1092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 980 KB Output is correct
2 Correct 9 ms 1104 KB Output is correct
3 Correct 11 ms 1104 KB Output is correct
4 Correct 11 ms 980 KB Output is correct
5 Correct 11 ms 1100 KB Output is correct
6 Correct 11 ms 980 KB Output is correct
7 Correct 10 ms 1104 KB Output is correct
8 Correct 10 ms 1104 KB Output is correct
9 Correct 13 ms 1104 KB Output is correct
10 Correct 63 ms 1080 KB Output is correct
11 Correct 167 ms 1076 KB Output is correct
12 Correct 237 ms 1084 KB Output is correct
13 Correct 304 ms 1084 KB Output is correct
14 Correct 292 ms 1084 KB Output is correct
15 Correct 282 ms 980 KB Output is correct
16 Correct 308 ms 1076 KB Output is correct
17 Correct 289 ms 980 KB Output is correct
18 Correct 277 ms 1100 KB Output is correct
19 Correct 284 ms 1100 KB Output is correct
20 Correct 34 ms 1092 KB Output is correct
21 Correct 15 ms 1108 KB Output is correct
22 Correct 300 ms 1096 KB Output is correct
23 Correct 32 ms 980 KB Output is correct
24 Correct 119 ms 1088 KB Output is correct
25 Correct 169 ms 980 KB Output is correct
26 Correct 231 ms 1080 KB Output is correct
27 Correct 259 ms 1076 KB Output is correct
28 Correct 225 ms 1084 KB Output is correct
29 Correct 249 ms 1096 KB Output is correct
30 Correct 278 ms 1076 KB Output is correct
31 Correct 286 ms 1096 KB Output is correct
32 Correct 230 ms 1084 KB Output is correct
33 Correct 240 ms 980 KB Output is correct
34 Correct 239 ms 1096 KB Output is correct
35 Correct 17 ms 1100 KB Output is correct
36 Correct 24 ms 980 KB Output is correct
37 Correct 180 ms 1092 KB Output is correct
38 Correct 16 ms 1108 KB Output is correct
39 Correct 10 ms 980 KB Output is correct
40 Correct 12 ms 1096 KB Output is correct
41 Correct 11 ms 1104 KB Output is correct
42 Correct 10 ms 980 KB Output is correct
43 Correct 10 ms 980 KB Output is correct
44 Correct 11 ms 980 KB Output is correct
45 Correct 276 ms 1088 KB Output is correct
46 Correct 267 ms 1080 KB Output is correct
47 Correct 15 ms 980 KB Output is correct
48 Correct 10 ms 980 KB Output is correct
49 Correct 9 ms 1100 KB Output is correct
50 Correct 9 ms 980 KB Output is correct
51 Correct 9 ms 1092 KB Output is correct
52 Correct 83 ms 980 KB Output is correct