이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ti = tuple<int,int,int>;
const int inf=1e9;
int n,m;
int dis[30005][305];
vector<int> bg[30005],sm[30005];
int b[30005],p[30005];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
int sq=sqrt(n);
for(int i=0;i<m;i++){
cin >> b[i] >> p[i];
if(p[i]<=sq)
sm[b[i]].push_back(p[i]);
else
bg[b[i]].push_back(p[i]);
}
for(int i=0;i<n;i++)
for(int j=0;j<=sq;j++)
dis[i][j]=inf;
priority_queue<ti,vector<ti>,greater<ti>> pq;
dis[b[0]][0]=0;
pq.push({0,b[0],0});
while(!pq.empty()){
auto [du,u,pw]=pq.top();
pq.pop();
if(du!=dis[u][pw])
continue;
if(pw){
if(u-pw>=0){
if(du+1<dis[u-pw][pw]){
dis[u-pw][pw]=du+1;
pq.push({du+1,u-pw,pw});
}
if(du+1<dis[u-pw][0]){
dis[u-pw][0]=du+1;
pq.push({du+1,u-pw,0});
}
}
if(u+pw<n){
if(du+1<dis[u+pw][pw]){
dis[u+pw][pw]=du+1;
pq.push({du+1,u+pw,pw});
}
if(du+1<dis[u+pw][0]){
dis[u+pw][0]=du+1;
pq.push({du+1,u+pw,0});
}
}
}
for(auto pl:bg[u]){
for(int v=u,cnt=0;v<n;v+=pl,cnt++){
if(dis[v][0]>du+cnt){
dis[v][0]=du+cnt;
pq.push({du+cnt,v,0});
}
}
for(int v=u,cnt=0;v>=0;v-=pl,cnt++){
if(dis[v][0]>du+cnt){
dis[v][0]=du+cnt;
pq.push({du+cnt,v,0});
}
}
}
for(auto pl:sm[u]){
if(dis[u][pl]>du){
dis[u][pl]=du;
pq.push({du,u,pl});
}
}
}
int mn=inf;
for(int i=0;i<=sq;i++)
mn=min(mn,dis[b[1]][i]);
if(mn==inf)
mn=-1;
cout << mn;
}
컴파일 시 표준 에러 (stderr) 메시지
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:35:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
35 | auto [du,u,pw]=pq.top();
| ^
# | 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... |