이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#define S 30007
#define M 300
using namespace std;
int B[S];
int P[S];
int n,m;
int odw[S];
int odw2[S][M+7];
vector < int > doge[S];
priority_queue < pair < int, pair < int , int > >, vector < pair < int , pair < int , int > > > , greater < pair < int , pair < int , int > > > > q;
void dijkstra(){
q.push({0,{0,B[0]}});
while(!q.empty()){
int koszt = q.top().first;
int pies = q.top().second.first;
int gdzie = q.top().second.second;
q.pop();
if(!odw[gdzie]){
for(int i = 0; i < doge[gdzie].size();i++){
if(P[doge[gdzie][i]] <= M){
q.push({koszt,{doge[gdzie][i],gdzie}});
}else{
int p = 0;
for(int j = gdzie; j >= 0; j -= P[doge[gdzie][i]]){
p++;
q.push({koszt+p,{doge[gdzie][i],j}});
}
p = 0;
for(int j = gdzie; j < n; j += P[doge[gdzie][i]]){
p++;
q.push({koszt+p,{doge[gdzie][i],j}});
}
}
}
odw[gdzie] = koszt+1;
}
if(P[pies] <= M){
if(!odw2[gdzie][P[pies]]){
odw2[gdzie][P[pies]] = 1;
if(gdzie - P[pies] >= 0)
q.push({koszt+1,{pies, gdzie - P[pies]}});
if(gdzie + P[pies] < n)
q.push({koszt+1,{pies, gdzie + P[pies]}});
}
}
}
}
int main(void){
scanf("%d %d",&n,&m);
for(int i = 0; i < m;i++){
scanf("%d %d",&B[i],&P[i]);
doge[B[i]].push_back(i);
}
dijkstra();
if(odw[B[1]]){
printf("%d",odw[B[1]]-1);
}else{
printf("-1");
}
return 0;
}
/*
5 3
0 2
1 1
4 1
*/
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'void dijkstra()':
skyscraper.cpp:29:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i = 0; i < doge[gdzie].size();i++){
| ~~^~~~~~~~~~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
skyscraper.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf("%d %d",&B[i],&P[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
# | 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... |