이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(101202);
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r) {
if (l > r) { cerr << l << " " << r << "\n"; }
return l + rng() % (r - l + 1);
}
vector<int> createFunTour(int n, int q) {
vector<vector<int>> distance(n, vector<int>(n));
for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) {
distance[i][j] = distance[j][i] = hoursRequired(i, j);
}
vector<int> state(n); iota(state.begin(), state.end(), 0);
function<int(const vector<int>&)> evaluate = [&](const vector<int> &state) {
int fault = 0;
for (int i = 2; i < state.size(); ++i) {
fault +=
distance[state[i - 2]][state[i - 1]] < distance[state[i - 1]][state[i]];
}
return fault;
};
int temperature = 1e7;
int best = evaluate(state);
while (best) {
int x = rnd(0, n - 1);
int y = rnd(0, n - 1);
if (x == y) continue;
swap(state[x], state[y]);
int adjValue = evaluate(state);
if (
adjValue < best
|| exp((best - adjValue) / temperature > rng() / (double)rng.max())
) best = adjValue;
else swap(state[x], state[y]);
temperature *= 0.9999;
}
return state;
}
컴파일 시 표준 에러 (stderr) 메시지
fun.cpp: In lambda function:
fun.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int i = 2; i < state.size(); ++i) {
| ~~^~~~~~~~~~~~~~
# | 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... |