# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
965945 | phoenix0423 | Fun Tour (APIO20_fun) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define q1 hoursRequired
#define q2 attrationsBehind
#include "fun.h"
const int maxn = 500 + 5;
const int INF = 1e9;
vector<int> adj[maxn];
int dist[maxn][maxn];
vector<int> sol1(int n){
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if(dist[i][j] != 1) dist[i][j] = INF;
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(q1(i, j) == 1){
dist[i][j] = dist[j][i] = 1;
}
}
}
for(int k = 0; k < n; k++){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
vector<int> ans;
for(int i = 0; i < n; i++){
vector<int> use(n);
ans.pb(i);
use[i] = 1;
while(ans.size() < n){
int mx = -1, lst = INF, prv = i;
for(int j = 0; j < n; j++){
if(use[j]) continue;
if(dist[prv][j] <= lst){
if(mx == -1 || dist[prv][j] > dist[prv][mx]) mx = j;
}
}
if(mx == -1) break;
use[mx] = 1, ans.pb(mx);
lst = dist[prv][mx];
prv = mx;
}
if(ans.size() == n) return ans;
}
return vector<int>();
}
std::vector<int> createFunTour(int n, int Q) {
if(n <= 500) return sol1(n);
}
Compilation message (stderr)
# | 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... |