이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) begin(x), end(x)
vector<int> createFunTour(int n, int q) {
const int infI = 1e9 + 7;
vector<vector<int>> dist(n, vector<int>(q));
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
dist[i][j] = dist[j][i] = hoursRequired(i, j);
}
}
int N = (1 << n);
vector<vector<int>> dp(N, vector<int>(n, infI)), p(N, vector<int>(n, -1));
for (int mask = 1; mask < N; ++mask) {
vector<int> now;
for (int i = 0; i < n; ++i) {
if ((mask >> i) & 1) {
now.push_back(i);
}
}
if (now.size() == 1) {
dp[mask][now[0]] = 0;
p[mask][now[0]] = -1;
} else {
for (int i : now) {
int msk = mask ^ (1 << i);
for (int j : now) {
if (i != j) {
if (dp[msk][j] <= dist[i][j] && dp[mask][i] > dist[i][j]) {
dp[mask][i] = dist[i][j];
p[mask][i] = j;
}
}
}
}
}
}
for (int i = 0; i < n; ++i) {
if (dp[N - 1][i] != infI) {
vector<int> ans;
int mask = N - 1;
while (i != -1) {
ans.push_back(i);
int msk = mask ^ (1 << i);
i = p[mask][i];
mask = msk;
}
return ans;
}
}
assert(false);
return {};
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |