結果

問題 No.2733 Just K-times TSP
ユーザー KKT89KKT89
提出日時 2024-04-19 22:05:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 4,154 bytes
コンパイル時間 3,199 ms
コンパイル使用メモリ 217,624 KB
実行使用メモリ 27,008 KB
最終ジャッジ日時 2024-04-19 22:05:39
合計ジャッジ時間 5,207 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
26,752 KB
testcase_01 AC 33 ms
26,880 KB
testcase_02 AC 31 ms
26,880 KB
testcase_03 AC 29 ms
26,932 KB
testcase_04 AC 30 ms
26,880 KB
testcase_05 AC 30 ms
27,008 KB
testcase_06 AC 30 ms
26,880 KB
testcase_07 AC 29 ms
26,884 KB
testcase_08 AC 29 ms
26,928 KB
testcase_09 AC 34 ms
27,008 KB
testcase_10 AC 30 ms
27,008 KB
testcase_11 AC 29 ms
27,008 KB
testcase_12 AC 31 ms
26,880 KB
testcase_13 AC 30 ms
26,880 KB
testcase_14 AC 34 ms
26,880 KB
testcase_15 AC 35 ms
26,880 KB
testcase_16 AC 30 ms
27,008 KB
testcase_17 AC 37 ms
26,996 KB
testcase_18 AC 38 ms
26,880 KB
testcase_19 AC 38 ms
27,008 KB
testcase_20 AC 30 ms
26,880 KB
testcase_21 AC 31 ms
26,924 KB
testcase_22 AC 43 ms
26,752 KB
testcase_23 AC 32 ms
27,008 KB
testcase_24 AC 44 ms
26,752 KB
testcase_25 AC 44 ms
26,880 KB
testcase_26 AC 30 ms
26,992 KB
testcase_27 AC 30 ms
27,008 KB
testcase_28 AC 30 ms
26,892 KB
testcase_29 AC 32 ms
26,908 KB
testcase_30 AC 34 ms
27,008 KB
testcase_31 AC 38 ms
27,008 KB
testcase_32 AC 48 ms
26,880 KB
testcase_33 AC 68 ms
26,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

template <int mod> struct static_modint {
    using mint = static_modint;
    int x;

    static_modint() : x(0) {}
    static_modint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    mint &operator+=(const mint &rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint &rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint &rhs) {
        x = (int)(1LL * x * rhs.x % mod);
        return *this;
    }
    mint &operator/=(const mint &rhs) { return *this = *this * rhs.inv(); }

    mint pow(long long n) const {
        mint _x = *this, r = 1;
        while (n) {
            if (n & 1) r *= _x;
            _x *= _x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const { return pow(mod - 2); }

    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }
    friend mint operator+(const mint &lhs, const mint &rhs) { return mint(lhs) += rhs; }
    friend mint operator-(const mint &lhs, const mint &rhs) { return mint(lhs) -= rhs; }
    friend mint operator*(const mint &lhs, const mint &rhs) { return mint(lhs) *= rhs; }
    friend mint operator/(const mint &lhs, const mint &rhs) { return mint(lhs) /= rhs; }
    friend bool operator==(const mint &lhs, const mint &rhs) { return lhs.x == rhs.x; }
    friend bool operator!=(const mint &lhs, const mint &rhs) { return lhs.x != rhs.x; }

    friend ostream &operator<<(ostream &os, const mint &p) { return os << p.x; }
    friend istream &operator>>(istream &is, mint &a) {
        int64_t t;
        is >> t;
        a = static_modint<mod>(t);
        return (is);
    }
};

const unsigned int mod = 998244353;
using modint = static_modint<mod>;
modint mod_pow(ll n, ll x) { return modint(n).pow(x); }
modint mod_pow(modint n, ll x) { return n.pow(x); }

modint dp[10][10][10][10][10][10][6];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        x -= 1, y -= 1;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for (int i = 0; i < n; ++i) {
        vector<int> u(6);
        u[i] = 1;
        dp[u[0]][u[1]][u[2]][u[3]][u[4]][u[5]][i] = 1;
    }

    for (int i = 0; i <= k; ++i) {
        for (int j = 0; j <= k; ++j) {
            for (int l = 0; l <= k; ++l) {
                for (int x = 0; x <= k; ++x) {
                    for (int y = 0; y <= k; ++y) {
                        for (int z = 0; z <= k; ++z) {
                            for (int s = 0; s < n; ++s) {
                                auto val = dp[i][j][l][x][y][z][s];
                                if (val == 0) continue;
                                for (int t : g[s]) {
                                    if (t == 0) dp[i + 1][j][l][x][y][z][t] += dp[i][j][l][x][y][z][s];
                                    if (t == 1) dp[i][j + 1][l][x][y][z][t] += dp[i][j][l][x][y][z][s];
                                    if (t == 2) dp[i][j][l + 1][x][y][z][t] += dp[i][j][l][x][y][z][s];
                                    if (t == 3) dp[i][j][l][x + 1][y][z][t] += dp[i][j][l][x][y][z][s];
                                    if (t == 4) dp[i][j][l][x][y + 1][z][t] += dp[i][j][l][x][y][z][s];
                                    if (t == 5) dp[i][j][l][x][y][z + 1][t] += dp[i][j][l][x][y][z][s];
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    modint res = 0;
    vector<int> u(6, 0);
    for (int i = 0; i < n; ++i) {
        u[i] = k;
    }
    for (int i = 0; i < n; ++i) {
        res += dp[u[0]][u[1]][u[2]][u[3]][u[4]][u[5]][i];
    }
    cout << res << endl;
}
0