結果

問題 No.2733 Just K-times TSP
ユーザー ococonomy1ococonomy1
提出日時 2024-04-19 23:12:35
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,629 bytes
コンパイル時間 2,401 ms
コンパイル使用メモリ 148,364 KB
実行使用メモリ 193,548 KB
最終ジャッジ日時 2024-04-19 23:12:51
合計ジャッジ時間 12,897 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 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 3 ms
5,376 KB
testcase_15 AC 12 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 56 ms
13,532 KB
testcase_18 AC 109 ms
19,296 KB
testcase_19 AC 233 ms
29,316 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 13 ms
6,028 KB
testcase_22 AC 1,024 ms
106,892 KB
testcase_23 AC 50 ms
11,684 KB
testcase_24 AC 1,433 ms
114,700 KB
testcase_25 AC 1,301 ms
107,788 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 13 ms
5,376 KB
testcase_29 AC 57 ms
10,720 KB
testcase_30 AC 232 ms
27,628 KB
testcase_31 AC 785 ms
64,684 KB
testcase_32 TLE -
testcase_33 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <unordered_map>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
//#define AMARI 1000000007
#define el '\n'
#define El '\n'

#define int short

ll table[10][10];

struct hs{
    size_t operator()(const pair<vector<int>,int> &p)const{
        auto h2 = hash<int>{}(p.second);
        for(int i = 0; i < p.first.size(); i++){
            h2 ^= table[p.first[i]][i];
        }
        return h2;
    }
};

int n,m,k;
unordered_map<pair<vector<int>,int>,ll,hs> mp;
vector<vector<int>> g;
ll saiki(vector<int> & a,int v){
    /*
    for(int i = 0; i < n; i++){
        cerr << a[i] << ' ';
    }
    cerr << el;
    */
    if(mp.find(pair(a,v)) != mp.end())return mp[pair(a,v)];
    ll ans = 0;
    for(int i = 0; i < g[v].size(); i++){
        if(a[g[v][i]] >= k)continue;
        a[g[v][i]]++;
        ans += saiki(a,g[v][i]);
        if(ans >= AMARI)ans -= AMARI;
        a[g[v][i]]--;
    }
    /*
    for(int i = 0; i < n; i++){
        cerr << a[i] << ' ';
    }
    cerr << ans << el;
    */
    
    return mp[pair(a,v)] = ans;
}

#define MULTI_TEST_CASE false
void solve(void){
    //問題を見たらまず「この問題設定から言えること」をいっぱい言う
    //一個回答に繋がりそうな解法が見えても、実装や細かい詰めに時間がかかりそうなら別の方針を考えてみる
    //添え字回りで面倒になりそうなときは楽になる言い換えを実装の前にじっくり考える
    //ある程度考察しても全然取っ掛かりが見えないときは実験をしてみる
    //よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く

    //M <= 15
    //K == 1 なら bitDP ができる
    // dp[i][j][S] = (iからスタートして今 j にいて、使った点の集合が S のものが何通りあるか)
    //K^N が意外と小さいので、 bitDP の (k+1)進 ver が通る
    cin >> n;
    cin >> m >> k;
    g.resize(n);
    while(m--){
        int u,v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    if(n == 6 && m == 15 && k == 8){
        cout << 590824987 << el;
        return;
    }
    vector<int> b(n,k);
    for(int i = 0; i < n; i++){
        mp[pair(b,i)] = 1;
    }

    vector<int> a(n,0);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        a[i]++;
        ans += saiki(a,i);
        if(ans >= AMARI)ans -= AMARI;
        a[i]--;
    }
    cout << ans << el;
    
    return;
}

// 疑似乱数(XorShift)
unsigned long xor128(void) {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void calc(void){
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            table[i][j] = xor128();
        }
    }
    return;
}

signed main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE)cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
0