이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
void dfs(int pos, int prev, int h, int d){
dist[h][pos] = d;
for(auto x : adj[pos]){
if(x == prev) continue;
dfs(x, pos, h, d + 1);
}
}
vector<int> sol1(int n){
for(int i = 0; i < n; i++){
for(int j = i + 1; j < n; j++){
if(q1(i, j) == 1){
adj[i].pb(j), adj[j].pb(i);
}
}
}
for(int i = 0; i < n; i++) dfs(i, -1, i, 0);
for(int i = 0; i < n; i++){
vector<int> ans;
vector<int> use(n);
ans.pb(i);
use[i] = 1;
int mx = -1, lst = INF, prv = i;
while(ans.size() < n){
mx = -1;
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;
assert(!use[mx]);
use[mx] = 1, ans.pb(mx);
lst = dist[prv][mx];
prv = mx;
}
if(ans.size() == n) return ans;
}
assert(false);
}
std::vector<int> createFunTour(int n, int Q) {
if(n <= 500) return sol1(n);
}
컴파일 시 표준 에러 (stderr) 메시지
fun.cpp: In function 'std::vector<int> sol1(int)':
fun.cpp:41:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
41 | while(ans.size() < n){
| ~~~~~~~~~~~^~~
fun.cpp:55:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
55 | if(ans.size() == n) return ans;
| ~~~~~~~~~~~^~~~
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
62 | }
| ^
# | 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... |