이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#include "game.h"
using namespace std;
vector<int> ind[2001];
int len[30001];
int n,m;
int nah;
long long d(int b){
long long cost[m][n];
for(int i = 0;i<m;i++)for(int j = 0;j<n;j++)cost[i][j] = 1e18;
priority_queue<pair<long long,pair<int,int>>> q1;
q1.push({0,{0,b}});
cost[0][b] = 0;
while(!q1.empty()){
long long co = q1.top().first*-1;
long long dog = q1.top().second.first;
long long indx = q1.top().second.second;
q1.pop();
if(co>cost[dog][indx]) continue ;
for(auto i:ind[indx]){
if(cost[i][indx]>(cost[dog][indx])){
cost[i][indx] = (cost[dog][indx]);
q1.push({cost[i][indx]*-1,{i,indx}});
}
}
if(indx+len[dog]>=0&&indx+len[dog]<n){
if(cost[dog][indx+len[dog]]>(cost[dog][indx]+1)){
cost[dog][indx+len[dog]] = (cost[dog][indx]+1);
q1.push({cost[dog][indx+len[dog]]*-1,{dog,indx+len[dog]}});
}
}
if(indx-len[dog]>=0&&indx-len[dog]<n){
if(cost[dog][indx-len[dog]]>(cost[dog][indx]+1)){
cost[dog][indx-len[dog]] = (cost[dog][indx]+1);
q1.push({cost[dog][indx-len[dog]]*-1,{dog,indx-len[dog]}});
}
}
}
return cost[1][nah];
}
int main(){
//ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m;
int z;
for(int i = 0;i<m;i++){
int x,b;
cin>>x>>b;
if(i==1)nah = x;
if(i==0)z = x;
len[i] = b;
ind[x].push_back(i);
}
//cout<<z<<" "<<nah<<"\n";
cout<<d(z);
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:54:14: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
54 | cout<<d(z);
| ^| # | 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... |