結果

問題 No.2733 Just K-times TSP
ユーザー KKT89
提出日時 2024-04-19 22:05:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 4,154 bytes
コンパイル時間 2,900 ms
コンパイル使用メモリ 222,280 KB
最終ジャッジ日時 2025-02-21 04:19:20
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0