답안 #411961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411961 2021-05-26T11:00:20 Z 반딧불(#7584) Semafor (COI20_semafor) C++17
79 / 100
203 ms 712 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll MOD = 1000000007;
const int state[10] = {10, 2, 9, 7, 18, 21, 12, 3, 29, 23};
const ll comb[6] = {1, 5, 10, 10, 5, 1};

ll mpow(ll x, ll y){
    ll ret = 1;
    while(y){
        if(y%2) ret = (ret*x) % MOD;
        x = (x*x) % MOD;
        y/=2;
    }
    return ret;
}

struct Matrix{
    int n, m;
    vector<vector<ll> > mat;
    Matrix(){}
    Matrix(int _n, int _m){
        n = _n, m = _m;
        mat.resize(n);
        for(int i=0; i<n; i++) mat[i].resize(m);
    }
    Matrix(vector<vector<ll> > mat): mat(mat){}

    Matrix operator*(const Matrix &r)const{
        int o = r.m;
        assert(m == r.n);
        Matrix ret(n, o);
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                for(int k=0; k<o; k++){
                    ret.mat[i][k] += mat[i][j] * r.mat[j][k];
                    ret.mat[i][k] %= MOD;
                }
            }
        }
        return ret;
    }
};

Matrix Default(int _n){
    Matrix mat(_n, _n);
    for(int i=0; i<_n; i++) mat.mat[i][i] = 1;
    return mat;
}

Matrix matPow(Matrix mat, ll y){
    assert(mat.n == mat.m);
    Matrix ret = Default(mat.n);
    while(y){
        if(y%2) ret = ret * mat;
        mat = mat * mat;
        y/=2;
    }
    return ret;
}

int m; ll n, k; int x;
Matrix byKMat;
Matrix ans;

int score(int i, int j){
    return i*6+j;
}

Matrix distanceK(ll k){
    Matrix newMat (36, 36);
    for(int i=0; i<=5; i++){
        for(int j=0; j<=5; j++){
            if(i) newMat.mat[score(i, j)][score(i-1, j)] = i;
            if(j) newMat.mat[score(i, j)][score(i, j-1)] = j;
            if(i<5) newMat.mat[score(i, j)][score(i+1, j)] = 5-i;
            if(j<5) newMat.mat[score(i, j)][score(i, j+1)] = 5-j;
        }
    }

    Matrix powered = matPow(newMat, k);
    Matrix atFirst = Matrix(1, 36);
    atFirst.mat[0][0] = 1;

    Matrix result = atFirst * powered;
    Matrix ret = Matrix(100, 100);
    for(int i=0; i<100; i++){
        for(int j=0; j<100; j++){
            int dist1 = __builtin_popcount(state[i/10] ^ state[j/10]);
            int dist2 = __builtin_popcount(state[i%10] ^ state[j%10]);
            ret.mat[i][j] = result.mat[0][score(dist1, dist2)] * mpow(comb[dist1], MOD-2) % MOD * mpow(comb[dist2], MOD-2) % MOD;
        }
    }

    return ret;
}

int main(){
    scanf("%d %lld %lld %d", &m, &n, &k, &x);
    ans = matPow(distanceK(k), n/k) * distanceK(n%k);
    for(int i=0; i<100; i++) printf("%lld\n", ans.mat[x][i]);
}

Compilation message

semafor.cpp: In function 'int main()':
semafor.cpp:101:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |     scanf("%d %lld %lld %d", &m, &n, &k, &x);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 620 KB Output is correct
2 Correct 15 ms 588 KB Output is correct
3 Correct 15 ms 632 KB Output is correct
4 Correct 16 ms 608 KB Output is correct
5 Correct 15 ms 636 KB Output is correct
6 Correct 18 ms 600 KB Output is correct
7 Correct 17 ms 628 KB Output is correct
8 Correct 17 ms 624 KB Output is correct
9 Correct 17 ms 628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 628 KB Output is correct
2 Correct 101 ms 588 KB Output is correct
3 Correct 135 ms 628 KB Output is correct
4 Correct 178 ms 628 KB Output is correct
5 Correct 203 ms 640 KB Output is correct
6 Correct 159 ms 540 KB Output is correct
7 Correct 171 ms 612 KB Output is correct
8 Correct 175 ms 608 KB Output is correct
9 Correct 164 ms 612 KB Output is correct
10 Correct 178 ms 604 KB Output is correct
11 Correct 28 ms 552 KB Output is correct
12 Correct 17 ms 628 KB Output is correct
13 Correct 170 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 628 KB Output is correct
2 Correct 101 ms 588 KB Output is correct
3 Correct 135 ms 628 KB Output is correct
4 Correct 178 ms 628 KB Output is correct
5 Correct 203 ms 640 KB Output is correct
6 Correct 159 ms 540 KB Output is correct
7 Correct 171 ms 612 KB Output is correct
8 Correct 175 ms 608 KB Output is correct
9 Correct 164 ms 612 KB Output is correct
10 Correct 178 ms 604 KB Output is correct
11 Correct 28 ms 552 KB Output is correct
12 Correct 17 ms 628 KB Output is correct
13 Correct 170 ms 624 KB Output is correct
14 Correct 27 ms 588 KB Output is correct
15 Correct 73 ms 712 KB Output is correct
16 Correct 107 ms 608 KB Output is correct
17 Correct 141 ms 628 KB Output is correct
18 Correct 148 ms 588 KB Output is correct
19 Correct 130 ms 608 KB Output is correct
20 Correct 157 ms 604 KB Output is correct
21 Correct 165 ms 608 KB Output is correct
22 Correct 163 ms 628 KB Output is correct
23 Correct 135 ms 628 KB Output is correct
24 Correct 142 ms 612 KB Output is correct
25 Correct 146 ms 612 KB Output is correct
26 Correct 23 ms 660 KB Output is correct
27 Correct 24 ms 588 KB Output is correct
28 Correct 109 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 620 KB Output is correct
2 Correct 15 ms 588 KB Output is correct
3 Correct 15 ms 632 KB Output is correct
4 Correct 16 ms 608 KB Output is correct
5 Correct 15 ms 636 KB Output is correct
6 Correct 18 ms 600 KB Output is correct
7 Correct 17 ms 628 KB Output is correct
8 Correct 17 ms 624 KB Output is correct
9 Correct 17 ms 628 KB Output is correct
10 Correct 43 ms 628 KB Output is correct
11 Correct 101 ms 588 KB Output is correct
12 Correct 135 ms 628 KB Output is correct
13 Correct 178 ms 628 KB Output is correct
14 Correct 203 ms 640 KB Output is correct
15 Correct 159 ms 540 KB Output is correct
16 Correct 171 ms 612 KB Output is correct
17 Correct 175 ms 608 KB Output is correct
18 Correct 164 ms 612 KB Output is correct
19 Correct 178 ms 604 KB Output is correct
20 Correct 28 ms 552 KB Output is correct
21 Correct 17 ms 628 KB Output is correct
22 Correct 170 ms 624 KB Output is correct
23 Correct 27 ms 588 KB Output is correct
24 Correct 73 ms 712 KB Output is correct
25 Correct 107 ms 608 KB Output is correct
26 Correct 141 ms 628 KB Output is correct
27 Correct 148 ms 588 KB Output is correct
28 Correct 130 ms 608 KB Output is correct
29 Correct 157 ms 604 KB Output is correct
30 Correct 165 ms 608 KB Output is correct
31 Correct 163 ms 628 KB Output is correct
32 Correct 135 ms 628 KB Output is correct
33 Correct 142 ms 612 KB Output is correct
34 Correct 146 ms 612 KB Output is correct
35 Correct 23 ms 660 KB Output is correct
36 Correct 24 ms 588 KB Output is correct
37 Correct 109 ms 612 KB Output is correct
38 Correct 20 ms 528 KB Output is correct
39 Correct 23 ms 588 KB Output is correct
40 Correct 25 ms 588 KB Output is correct
41 Correct 30 ms 592 KB Output is correct
42 Correct 35 ms 516 KB Output is correct
43 Correct 32 ms 544 KB Output is correct
44 Correct 53 ms 528 KB Output is correct
45 Correct 160 ms 612 KB Output is correct
46 Correct 167 ms 620 KB Output is correct
47 Correct 32 ms 588 KB Output is correct
48 Correct 25 ms 548 KB Output is correct
49 Correct 22 ms 552 KB Output is correct
50 Correct 15 ms 588 KB Output is correct
51 Correct 16 ms 588 KB Output is correct
52 Correct 67 ms 628 KB Output is correct