Submission #927320

#TimeUsernameProblemLanguageResultExecution timeMemory
927320TAhmed33즐거운 행로 (APIO20_fun)C++17
10 / 100
58 ms148892 KiB
#include <bits/stdc++.h> #include "fun.h" using namespace std; int adj[17][17]; int dp[17][17][1 << 17]; vector <int> ret; int n; int ans (int a, int b, int mask) { int &ret = dp[a][b][mask]; if (ret != -1) return ret; if (mask == 0) return ret = 1; ret = 0; for (int i = 0; i < n; i++) { if (mask & (1 << i)) { if (adj[a][b] >= adj[b][i]) { ret |= ans(b, i, mask ^ (1 << i)); } } } return ret; } void reconstruct (int a, int b, int mask) { //cout << a << " " << b << " " << mask << '\n'; if (mask == 0) return; for (int i = 0; i < n; i++) { if (mask & (1 << i)) { if (adj[a][b] >= adj[b][i] && dp[b][i][mask ^ (1 << i)]) { ret.push_back(i); reconstruct(b, i, mask ^ (1 << i)); return; } } } } vector <int> createFunTour (int N, int q) { n = N; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { adj[i][j] = hoursRequired(i, j); } } memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; if (ans(i, j, ((1 << n) - 1) ^ (1 << i) ^ (1 << j))) { ret.push_back(i); ret.push_back(j); reconstruct(i, j, ((1 << n) - 1) ^ (1 << i) ^ (1 << j)); // for (auto i : ret) cout << i << " "; // cout << '\n'; return ret; } } } assert(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...