結果
問題 | No.2733 Just K-times TSP |
ユーザー |
![]() |
提出日時 | 2024-04-19 23:05:20 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,895 bytes |
コンパイル時間 | 17,501 ms |
コンパイル使用メモリ | 328,044 KB |
最終ジャッジ日時 | 2025-02-21 05:21:30 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 31 TLE * 1 |
ソースコード
#include<bits/stdc++.h>using namespace std;//* ATCODER#include<atcoder/all>using namespace atcoder;typedef modint998244353 mint;//*//* BOOST MULTIPRECISION#include<boost/multiprecision/cpp_int.hpp>using namespace boost::multiprecision;//*/typedef long long ll;#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)template <typename T> bool chmin(T &a, const T &b) {if (a <= b) return false;a = b;return true;}template <typename T> bool chmax(T &a, const T &b) {if (a >= b) return false;a = b;return true;}template <typename T> T max(vector<T> &a){assert(!a.empty());T ret = a[0];for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);return ret;}template <typename T> T min(vector<T> &a){assert(!a.empty());T ret = a[0];for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);return ret;}template <typename T> T sum(vector<T> &a){T ret = 0;for (int i=0; i<(int)a.size(); i++) ret += a[i];return ret;}int main(){ios_base::sync_with_stdio(false);cin.tie(NULL);int n,m,k;cin >> n >> m >> k;vector edge(n, vector<bool>(n));rep(i,0,m){int a, b; cin >> a >> b;a--; b--;edge[a][b] = 1;edge[b][a] = 1;}unordered_map<int,mint> mp;rep(i,0,n){mp[i<<24] = 1;}auto calc = [&](auto self, int state) -> mint {int i = state>>24;if (mp.find(state) != mp.end()) return mp[state];mint ret = 0;rep(j,0,n){if (edge[i][j]){if ((state>>(j*4)&15)==0) continue;state-=1<<(j*4);state-=i<<24;state+=j<<24;ret += self(self,state);state-=j<<24;state+=i<<24;state+=1<<(j*4);}}mp[state]=ret;return ret;};mint ans=0;rep(i,0,n){int state=0;rep(j,0,n){state+=k<<(j*4);}state+=i<<24;state-=1<<(i*4);ans += calc(calc,state);}cout << ans.val() << '\n';}