結果

問題 No.2711 Connecting Lights
ユーザー novaandcabralnovaandcabral
提出日時 2024-06-29 20:08:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 7,352 bytes
コンパイル時間 1,670 ms
コンパイル使用メモリ 173,224 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-29 20:08:34
合計ジャッジ時間 2,563 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
6,940 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 3 ms
6,944 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
6,940 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 3 ms
6,940 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef vector<string> vst;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef pair<long long, long long> P;

const long long MOD = 998244353;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T1, typename T2> istream& operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); ++i) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }

template <long long Modulus>
struct ModInt {
    long long val;
    constexpr ModInt(const long long _val = 0) noexcept : val(_val) {
        normalize();
    }
    void normalize() {
        val = (val % Modulus + Modulus) % Modulus;
    }
    inline ModInt& operator+=(const ModInt& rhs) noexcept {
        if (val += rhs.val, val >= Modulus) val -= Modulus;
        return *this;
    }
    inline ModInt& operator-=(const ModInt& rhs) noexcept {
        if (val -= rhs.val, val < 0) val += Modulus;
        return *this;
    }
    inline ModInt& operator*=(const ModInt& rhs) noexcept {
        val = val * rhs.val % Modulus;
        return *this;
    }
    inline ModInt& operator/=(const ModInt& rhs) noexcept {
        val = val * inv(rhs.val).val % Modulus;
        return *this;
    }
    ModInt inv() const {
        return inv(val);
    }
    ModInt pow(long long n) {
        assert(0 <= n);
        ModInt x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    ModInt inv(const long long n) const {
        long long a = n, b = Modulus, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= Modulus;
        if (u < 0) u += Modulus;
        return u;
    }
    friend inline ModInt operator+(const ModInt& lhs, const ModInt& rhs) noexcept { return ModInt(lhs) += rhs; }
    friend inline ModInt operator-(const ModInt& lhs, const ModInt& rhs) noexcept { return ModInt(lhs) -= rhs; }
    friend inline ModInt operator*(const ModInt& lhs, const ModInt& rhs) noexcept { return ModInt(lhs) *= rhs; }
    friend inline ModInt operator/(const ModInt& lhs, const ModInt& rhs) noexcept { return ModInt(lhs) /= rhs; }
    friend inline bool operator==(const ModInt& lhs, const ModInt& rhs) noexcept { return lhs.val == rhs.val; }
    friend inline bool operator!=(const ModInt& lhs, const ModInt& rhs) noexcept { return lhs.val != rhs.val; }
    friend inline istream& operator>>(istream& is, ModInt& x) noexcept {
        is >> x.val;
        x.normalize();
        return is;
    }
    friend inline ostream& operator<<(ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

using mint = ModInt<998244353>;

template <typename T>
struct Matrix {
    int n, m;
    vector<T> val;
    Matrix(int _n, int _m) : n(_n), m(_m), val(_n * _m) {}
    Matrix(const vector<vector<T>>& mat) {
        n = mat.size();
        m = mat[0].size();
        val.resize(n * m);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                val[i * m + j] = mat[i][j];
            }
        }
    }
    static Matrix e(int _n) {
        Matrix res(_n, _n);
        for (int i = 0; i < _n; ++i) {
            res[i][i] = T{1};
        }
        return res;
    }
    auto operator[](int i) { return val.begin() + i * m; }
    auto operator[](int i) const { return val.begin() + i * m; }
    inline Matrix& operator+=(const Matrix& rhs) {
        for (int i = 0; i < n * m; ++i) {
            val[i] += rhs[i];
        }
        return *this;
    }
    inline Matrix& operator-=(const Matrix& rhs) {
        for (int i = 0; i < n * m; ++i) {
            val[i] -= rhs[i];
        }
        return *this;
    }
    inline Matrix operator*(const Matrix& rhs) {
        assert(m == rhs.n);
        const int l = rhs.m;
        Matrix res(n, l);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                for (int k = 0; k < l; ++k) {
                    res[i][k] += val[i * m + j] * rhs[j][k];
                }
            }
        }
        return res;
    }
    inline Matrix& operator*=(const Matrix& rhs) {
        return *this = *this * rhs;
    }
    friend inline Matrix operator+(const Matrix& lhs, const Matrix& rhs) noexcept { return Matrix(lhs) += rhs; }
    friend inline Matrix operator-(const Matrix& lhs, const Matrix& rhs) noexcept { return Matrix(lhs) -= rhs; }
    friend inline bool operator==(const Matrix& lhs, const Matrix& rhs) noexcept { return lhs.val == rhs.val; }
    friend inline bool operator!=(const Matrix& lhs, const Matrix& rhs) noexcept { return lhs.val != rhs.val; }
    friend inline ostream& operator<<(ostream& os, const Matrix& mat) noexcept {
        const int _n = mat.n;
        const int _m = mat.m;
        for (int i = 0; i < _n; ++i) {
            for (int j = 0; j < _m; ++j) {
                os << mat[i][j] << " \n"[j == _m - 1];
            }
        }
        return os;
    }
    Matrix inv() const {
        Matrix a = *this, b = e(n);
        for (int i = 0; i < n; ++i) {
            if (a[i][i] == 0) {
                for (int j = i + 1; j < n; ++j) {
                    if (a[j][i] != 0) {
                        for (int k = i; k < n; ++k) swap(a[i][k], a[j][k]);
                        for (int k = 0; k < n; ++k) swap(b[i][k], b[j][k]);
                        break;
                    }
                }
            }
            if (a[i][i] == 0) throw "Inverse does not exist.";
            const T x = T{1} / a[i][i];
            for (int k = i; k < n; ++k) a[i][k] *= x;
            for (int k = 0; k < n; ++k) b[i][k] *= x;
            for (int j = 0; j < n; ++j) {
                if (i != j) {
                    const T x = a[j][i];
                    for (int k = i; k < n; ++k) a[j][k] -= a[i][k] * x;
                    for (int k = 0; k < n; ++k) b[j][k] -= b[i][k] * x;
                }
            }
        }
        return b;
    }
    Matrix pow(long long r) const {
        if (r == 0) return e(n);
        Matrix res = e(n);
        Matrix x = *this;
        while (r) {
            if (r & 1) res *= x;
            x *= x;
            r >>= 1;
        }
        return res;
    }
};

int main() {
    int n,m,k;
    cin>>n>>m>>k;
    Matrix<mint> mat(1LL << n, 1LL << n), def(1LL << n, 1LL);
    for(int i=0;i<(1ll<<n);i++)def[i][0]=1;
    for(int i=0;i<(1ll<<n);i++){
        for(int j=0;j<(1ll<<n);j++) if(__builtin_popcountll(i&j)<k) continue;
        else mat[i][j]+=1;
    }
    mat.pow(m-1);
    mat = mat * def;
    mint ans=0;
    for(int i=0;i<(1ll<<n);++i) ans=ans+mat[i][0];
    cout<<ans;
    return 0;
}
0