結果

問題 No.2733 Just K-times TSP
ユーザー GGanariGGanari
提出日時 2024-04-19 23:15:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 948 ms / 2,000 ms
コード長 1,228 bytes
コンパイル時間 2,112 ms
コンパイル使用メモリ 200,200 KB
実行使用メモリ 265,808 KB
最終ジャッジ日時 2024-04-19 23:16:29
合計ジャッジ時間 9,924 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
265,588 KB
testcase_01 AC 155 ms
265,668 KB
testcase_02 AC 154 ms
265,704 KB
testcase_03 AC 155 ms
265,496 KB
testcase_04 AC 154 ms
265,612 KB
testcase_05 AC 189 ms
265,640 KB
testcase_06 AC 121 ms
265,592 KB
testcase_07 AC 144 ms
265,572 KB
testcase_08 AC 120 ms
265,692 KB
testcase_09 AC 138 ms
265,808 KB
testcase_10 AC 119 ms
265,612 KB
testcase_11 AC 118 ms
265,696 KB
testcase_12 AC 120 ms
265,636 KB
testcase_13 AC 120 ms
265,468 KB
testcase_14 AC 122 ms
265,736 KB
testcase_15 AC 122 ms
265,656 KB
testcase_16 AC 163 ms
265,804 KB
testcase_17 AC 141 ms
265,684 KB
testcase_18 AC 149 ms
265,632 KB
testcase_19 AC 176 ms
265,556 KB
testcase_20 AC 125 ms
265,664 KB
testcase_21 AC 127 ms
265,680 KB
testcase_22 AC 268 ms
265,736 KB
testcase_23 AC 134 ms
265,628 KB
testcase_24 AC 409 ms
265,560 KB
testcase_25 AC 342 ms
265,724 KB
testcase_26 AC 122 ms
265,768 KB
testcase_27 AC 120 ms
265,740 KB
testcase_28 AC 127 ms
265,612 KB
testcase_29 AC 138 ms
265,624 KB
testcase_30 AC 206 ms
265,540 KB
testcase_31 AC 276 ms
265,760 KB
testcase_32 AC 476 ms
265,600 KB
testcase_33 AC 948 ms
265,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define INF 1000000001LL
#define LNF 1000000000000000001LL
#define MOD 998244353LL
#define MAX 1005
#define long long long
#define all(x) x.begin(),x.end()
using namespace std;

int mp[1<<26];
vector<int> graph[10];
int convert(vector<int> arr)
{
    int res = 0;

    int cur = 1;
    for(int i = 0; i<arr.size(); i++)
    {
        res+=cur*arr[i];
        cur*=9;
    }
    return res;
}
long dfs(int x,vector<int> cur, int sum)
{
    if(sum == 0)
        return 1;
    int p = convert(cur);
    if(mp[p] != -1)
        return mp[p];
    mp[p] = 0;
    auto &t = mp[p];
    for(int y : graph[x])
    {
        if(cur[y] == 0)
            continue;
        cur[0] = y;
        cur[y]--;
        t= (t+dfs(y,cur,sum-1))%MOD;
        cur[y]++;
    }
    return t;
}
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);
    
    memset(mp,-1,sizeof mp);
    int n,m,k;
    cin >> n >> m >> k;

    for(int i = 0; i<m; i++)
    {
        int a,b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> vis(n+1,k);
    vis[0] = 0;
    for(int i = 1; i<=n; i++)
        graph[0].push_back(i);

    cout << dfs(0,vis,k*n) << endl;

    return 0;
}
0