結果

問題 No.2733 Just K-times TSP
ユーザー KKT89KKT89
提出日時 2024-04-19 21:42:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,216 bytes
コンパイル時間 4,107 ms
コンパイル使用メモリ 233,428 KB
実行使用メモリ 172,764 KB
最終ジャッジ日時 2024-04-19 21:42:15
合計ジャッジ時間 12,089 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 35 ms
6,752 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 192 ms
19,812 KB
testcase_18 AC 370 ms
30,428 KB
testcase_19 AC 763 ms
46,436 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 50 ms
8,032 KB
testcase_22 TLE -
testcase_23 AC 204 ms
17,884 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

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); }

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);
    }
    using vp = pair<vector<int>, int>;
    map<vp, modint> dp;
    vector<vp> v;
    for (int i = 0; i < n; ++i) {
        vector<int> u(n);
        u[i] = 1;
        dp[{u, i}] = 1;
        v.push_back({u, i});
    }
    for (int l = 0; l < v.size(); ++l) {
        auto vec = v[l].first;
        int i = v[l].second;
        auto cost = dp[v[l]];
        for (int j : g[i]) {
            if (vec[j] == k) continue;
            vec[j] += 1;
            if (dp.find({vec, j}) == dp.end()) {
                v.push_back({vec, j});
            }
            dp[{vec, j}] += cost;
            vec[j] -= 1;
        }
    }

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