답안 #381618

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
381618 2021-03-25T10:59:45 Z kartel Semafor (COI20_semafor) C++14
18 / 100
111 ms 37484 KB
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#include <time.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define M ll(1e9 + 7)
//#define M ll(998244353)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
#define vi vector<int>
#define eps (ld)1e-9
using namespace std;
typedef long long ll;
//using namespace __gnu_pbds;
//typedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef double ld;
typedef unsigned long long ull;
typedef short int si;

ll sum(ll x, ll y) {return (x + y) % M;}
ll mult(ll x, ll y) {return (x * 1ll * y) % M;}

int digits[10] = {10, 2, 9, 7, 18, 21, 12, 3, 29, 23};



bool isd[(1 << 6)];
ll n, m, k, x;
int f[1505][(1 << 6)][(1 << 6)];
int dp[1505][(1 << 6)][(1 << 6)];

ll bp(ll x, ll y) {
    if (y == 0) { return 1;}
    if (y & 1) {
        return mult(x, bp(x, y - 1));
    }
    ll a = bp(x, y >> 1);
    return mult(a, a);
}

int main()
{
//    mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());;
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	in("toys.in");
//	out("toys.out");
//    in("input.txt");
//    out("output.txt");
//    cerr.precision(9); cerr << fixed;

//    clock_t tStart = clock();

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

    if (m == 1) {
        f[0][digits[x]][0] = 1;

        for (int i = 0; i < 10; i++) {
            isd[digits[i]] = 1;
        }

        for (int i = 0; i <= n; i++) {
            if (i % k == 0) {
                for (int mask = 0; mask < (1 << 5); mask++) {
                    if (!isd[mask]) {
                        f[i][mask][0] = 0;
                    }
                }
            }

            for (int mask = 0; mask < (1 << 5); mask++) {
                for (int j = 0; j < 5; j++) {
                    int nmask = (mask ^ (1 << j));
                    f[i + 1][nmask][0] = sum(f[i + 1][nmask][0], f[i][mask][0]);
                }
            }
        }

        for (int i = 0; i <= 9; i++) {
            cout << f[n][digits[i]][0] << el;
        }
    }
    else {
        string s = to_string(x);
        if (sz(s) == 1) {
            s = "0" + s;
        }

        int x = s[0] - '0';
        int y = s[1] - '0';

        f[0][digits[x]][digits[y]] = 1;

        for (int i = 0; i < 10; i++) {
            isd[digits[i]] = 1;
        }

        for (int i = 0; i <= k; i++) {
            if (i % k == 0) {
                for (int maskx = 0; maskx < (1 << 5); maskx++) {
                    for (int masky = 0; masky < (1 << 5); masky++) {
                        if (!isd[maskx] || !isd[masky]) {
                            f[i][maskx][masky] = 0;
                        }
                    }
                }
            }

            for (int maskx = 0; maskx < (1 << 5); maskx++) {
                for (int masky = 0; masky < (1 << 5); masky++) {
                    for (int j = 0; j < 5; j++) {
                        int nmask = (maskx ^ (1 << j));
                        f[i + 1][nmask][masky] = sum(f[i + 1][nmask][masky], f[i][maskx][masky]);

                        nmask = (masky ^ (1 << j));
                        f[i + 1][maskx][nmask] = sum(f[i + 1][maskx][nmask], f[i][maskx][masky]);
                    }
                }
            }
        }

        n -= k;

        for (int maskx = 0; maskx < (1 << 5); maskx++) {
            for (int masky = 0; masky < (1 << 5); masky++) {
                if (f[k][maskx][masky]) {
                    dp[0][maskx][masky] = 1;
                }
            }
        }
        int ost = n % k;

        for (int i = 0; i <= k; i++) {
            for (int maskx = 0; maskx < (1 << 5); maskx++) {
                for (int masky = 0; masky < (1 << 5); masky++) {
                    for (int j = 0; j < 5; j++) {
                        int nmask = (maskx ^ (1 << j));
                        dp[i + 1][nmask][masky] = sum(dp[i + 1][nmask][masky], dp[i][maskx][masky]);

                        nmask = (masky ^ (1 << j));
                        dp[i + 1][maskx][nmask] = sum(dp[i + 1][maskx][nmask], dp[i][maskx][masky]);
                    }
                }
            }
        }

        for (int maskx = 0; maskx < (1 << 5); maskx++) {
            for (int masky = 0; masky < (1 << 5); masky++) {
                f[0][maskx][masky] = mult(f[k][maskx][masky], bp(dp[k][maskx][masky], n / k));
            }
        }

        for (int i = 0; i <= ost; i++) {
            for (int maskx = 0; maskx < (1 << 5); maskx++) {
                for (int masky = 0; masky < (1 << 5); masky++) {
                    for (int j = 0; j < 5; j++) {
                        int nmask = (maskx ^ (1 << j));
                        f[i + 1][nmask][masky] = sum(f[i + 1][nmask][masky], f[i][maskx][masky]);

                        nmask = (masky ^ (1 << j));
                        f[i + 1][maskx][nmask] = sum(f[i + 1][maskx][nmask], f[i][maskx][masky]);
                    }
                }
            }
        }

        for (int i = 0; i <= 99; i++) {
            string s = to_string(i);

            if (i <= 9) {
                s = "0" + s;
            }

            int x = s[0] - '0';
            int y = s[1] - '0';

            cout << f[ost][digits[x]][digits[y]] << el;
        }
    }
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Runtime error 51 ms 37484 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 9 ms 2796 KB Output is correct
3 Correct 89 ms 24428 KB Output is correct
4 Correct 89 ms 28288 KB Output is correct
5 Correct 86 ms 28268 KB Output is correct
6 Correct 105 ms 31980 KB Output is correct
7 Correct 111 ms 36424 KB Output is correct
8 Correct 110 ms 36460 KB Output is correct
9 Correct 81 ms 27116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 9 ms 2796 KB Output is correct
3 Correct 89 ms 24428 KB Output is correct
4 Correct 89 ms 28288 KB Output is correct
5 Correct 86 ms 28268 KB Output is correct
6 Correct 105 ms 31980 KB Output is correct
7 Correct 111 ms 36424 KB Output is correct
8 Correct 110 ms 36460 KB Output is correct
9 Correct 81 ms 27116 KB Output is correct
10 Incorrect 2 ms 620 KB Output isn't correct
11 Halted 0 ms 0 KB -