이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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) {
if (mask == 0) return;
for (int i = 0; i < n; i++) {
if (mask & (1 << i)) {
if (adj[a][b] >= adj[b][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));
return ret;
}
}
}
assert(0);
}
# | 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... |