이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using pii=pair<int,int>;
set<pair<pii,int>> dp;
priority_queue<pair<int,pii>, vector<pair<int,pii>>, greater<pair<int,pii>>> que;
int n,m;
vector<int> arr[30000];
inline int abs(int a) {return a<0 ? -a : a;}
void push_val(int a,int b,int c) {
if(a+b<0 || a+b>=n) return;
pii idx = pii(a+b, abs(b));
auto it = dp.lower_bound({idx,0});
if(it==dp.end() || it->first!=idx) {
dp.insert({idx,c});
que.push({c,idx});
} else if(it->second > c) {
dp.erase(it);
dp.insert({idx, c});
que.push({c,idx});
}
}
int main() {
int ei;
scanf("%d%d",&n,&m);
for(int i=0,a,b;i<m;i++) {
scanf("%d%d",&a,&b);
arr[a].push_back(b);
if(i==0) {
dp.insert({{a,0},0});
que.push({0,{a,0}});
} else if(i==1) {
ei = a;
}
}
while(!que.empty()) {
int cost=que.top().fi, pos=que.top().se.fi, pv=que.top().se.se;
que.pop();
push_val(pos,-pv,cost+1);
push_val(pos,pv,cost+1);
while(!arr[pos].empty()) {
int pp=arr[pos].back();arr[pos].pop_back();
push_val(pos-pp,pp,cost);
}
}
int mx = -1;
for(auto &v : dp) if(v.fi.fi==ei) {
if(mx==-1 || mx > v.se) mx = v.se;
}
printf("%d\n",mx);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&a,&b);
~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:54:23: warning: 'ei' may be used uninitialized in this function [-Wmaybe-uninitialized]
for(auto &v : dp) if(v.fi.fi==ei) {
^~
# | 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... |