이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "rail.h"
using namespace std;
typedef int ll;
const ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
void findLocation(int n, int first, int location[], int stype[]){
location[0] = first;
stype[0] = 1;
ll dist[n][n];
f(i,0,n){
dist[i][i] = 0;
f(j,i+1,n){
ll v = getDistance(i,j);
dist[i][j] = dist[j][i] = v;
}
}
ll mini = INF;
ll pos;
f(i,1,n){
if(mini > dist[0][i]){
mini = dist[0][i];
pos = i;
}
}
stype[pos] = 2;
location[pos] = first + dist[0][pos];
ll ex = 2;
bool v[n] = {0};
v[0] = v[pos] = 1;
iii dista[n];
f(i,0,n){
dista[i] = iii(INF,ii(0,0));
}
f(i,0,n){
if(dista[i].F > dist[0][i]){
dista[i] = iii(dist[0][i],ii(i,0));
}
if(dista[i].F > dist[pos][i]){
dista[i] = iii(dist[pos][i],ii(i,pos));
}
}
while(ex != n){
ll prev;
mini = INF;
f(i,0,n){
if(!v[i] && mini > dista[i].F){
mini = dista[i].F;
prev = dista[i].S.S;
pos = dista[i].S.F;
}
}
if(stype[prev] == 1){
stype[pos] = 2;
location[pos] = location[prev] + mini;
}
else{
stype[pos] = 1;
location[pos] = location[prev] - mini;
}
v[pos] = 1;
ex++;
f(i,0,n){
if(dista[i].F > dist[pos][i]){
dista[i] = iii(dist[pos][i],ii(i,pos));
}
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:72:18: warning: 'prev' may be used uninitialized in this function [-Wmaybe-uninitialized]
72 | if(stype[prev] == 1){
| ^~~~
rail.cpp:46:40: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
46 | location[pos] = first + dist[0][pos];
| ~~~~~~~~~~~^
# | 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... |