Submission #557780

# Submission time Handle Problem Language Result Execution time Memory
557780 2022-05-06T03:12:43 Z Yazan_Alattar Semafor (COI20_semafor) C++14
21 / 100
12 ms 392 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 10007;
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const double eps = 1e-6;
const int dx[] = {0, -1, 0, 1}, dy[] = {1, 0, -1, 0};
const int block = 320;

struct Matrix{
    vector < vector <ll> > a = vector < vector <ll> > (32, (vector <ll> (32)));

    Matrix operator *(Matrix b){
        Matrix ret;
        for(int i = 0; i < 32; ++i) for(int j = 0; j < 32; ++j) for(int k = 0; k < 32; ++k){
            ret.a[i][k] = (ret.a[i][k] + (a[i][j] * b.a[j][k])) % mod;
        }
        return ret;
    }

};

Matrix Pow(Matrix x, ll p)
{
    Matrix ret;
    for(int i = 0; i < 32; ++i) ret.a[i][i] = 1;
    while(p){
        if(p % 2) ret = ret * x;
        x = x * x;
        p /= 2;
    }
    return ret;
}

ll m, n, k, x, sticks[M], ans[20];
bool vist[50];

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    // =======Construction=========
    sticks[1] = 2;  sticks[2] = 9;
    sticks[3] = 7;  sticks[4] = 18;
    sticks[5] = 21; sticks[6] = 12;
    sticks[7] = 3;  sticks[8] = 29;
    sticks[9] = 23; sticks[0] = 10;

    vist[2]  = vist[9]  = 1;
    vist[7]  = vist[18] = 1;
    vist[21] = vist[12] = 1;
    vist[3]  = vist[29] = 1;
    vist[23] = vist[10] = 1;
    // =============================

    cin >> m >> n >> k >> x;

    Matrix init;
    for(int i = 0; i < 32; ++i) for(int j = 0; j < 5; ++j) init.a[i][i ^ (1 << j)] = 1;
    Matrix res = Pow(init, k);
    Matrix FinalRes = Pow(init, n % k);

    for(int i = 0; i < 32; ++i) for(int j = 0; j < 32; ++j) init.a[i][j] = 0;
    for(int i = 0; i <= 9; ++i) for(int j = 0; j <= 9; ++j) init.a[sticks[i]][sticks[j]] = res.a[sticks[i]][sticks[j]];
    Matrix dpRes = Pow(init, n / k - 1);

    for(int i = 0; i <= 9; ++i)
        for(int j = 0; j <= 9; ++j)
            for(int l = 0; l <= 9; ++l)
                ans[i] = (ans[i] + ((res.a[sticks[x]][sticks[j]] * dpRes.a[sticks[j]][sticks[l]]) % mod) * FinalRes.a[sticks[l]][sticks[i]]) % mod;

    for(int i = 0; i <= 9; ++i) cout << ans[i] << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 5 ms 340 KB Output is correct
13 Correct 8 ms 388 KB Output is correct
14 Correct 10 ms 392 KB Output is correct
15 Correct 10 ms 332 KB Output is correct
16 Correct 11 ms 340 KB Output is correct
17 Correct 10 ms 332 KB Output is correct
18 Correct 6 ms 340 KB Output is correct
19 Correct 6 ms 340 KB Output is correct
20 Correct 12 ms 384 KB Output is correct
21 Correct 6 ms 340 KB Output is correct
22 Correct 6 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -