이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
int main(){
ll l,n;
cin >> l >> n;
vii v(n);
for (ll i=0;i<n;i++) cin >> v[i].first >> v[i].second;
pii in=v[0];
pii fin=v[1];
sort(v.begin(),v.end());
int inicio,final;
for (int i=0;i<n;i++){
if (v[i]==in) inicio=i;
if (v[i]==fin) final=i;
}
vvii conexiones(n);
for (ll i=0;i<n;i++){
pii x=v[i];
for (ll j=i-1;j>=0;j--){
pii y=v[j];
if (y.first%x.second==x.first%x.second) conexiones[i].push_back(pii{abs(x.first-y.first)/x.second,j});
if (x.second==y.second) break;
}
for (ll j=i+1;j<n;j++){
pii y=v[j];
if (y.first%x.second==x.first%x.second) conexiones[i].push_back(pii{abs(x.first-y.first)/x.second,j});
if (x.second==y.second) break;
}
}
priority_queue<pii> cola;
cola.push(pii{0,inicio});
bool T=true;
vi porvisitar(n,true);
//for (int i=0;i<n;i++){
// for (pii x:conexiones[i]) cerr << x.second<<x.first<<' ';
// cerr<<'\n';
//}
while (cola.size()){
pii x=cola.top();
cola.pop();
if (porvisitar[x.second]){
porvisitar[x.second]=false;
if (x.second==final){
T=false;
cout << -x.first << '\n';
break;
}
for (pii y:conexiones[x.second]){
if (porvisitar[y.second]) cola.push(pii{x.first-y.first,y.second});
}
}
}
if (T) cout << -1<<'\n';
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:52:27: warning: 'final' may be used uninitialized in this function [-Wmaybe-uninitialized]
52 | if (x.second==final){
| ^~~~~
# | 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... |