# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
146011 | mhy908 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 4 ms | 2168 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define inf 987654321
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
int n, m;
int b[30010], p[30010];
int dijk[30010];
priority_queue<pii> pq;
vector<int> jump[30010];
void dijkstra(int st)
{
pq.push({0, st});
dijk[st]=0;
while(!pq.empty()){
pii y=pq.top();
int here=y.S, th=-y.F;
pq.pop();
if(dijk[here]<th)continue;
for(int i=0; i<jump[here].size(); i++){
for(int j=here-jump[here][i]; j>=0; j-=jump[here][i]){
if(dijk[j]>dijk[here]+(here-j)/jump[here][i]){
dijk[j]=dijk[here]+(here-j)/jump[here][i];
pq.push({-dijk[j], j});
if((*lower_bound(jump[j].begin(), jump[j].end(), jump[here][i]))==jump[here][i])break;
}
}
for(int j=here+jump[here][i]; j<n; j+=jump[here][i]){
if(dijk[j]>dijk[here]+(j-here)/jump[here][i]){
dijk[j]=dijk[here]+(j-here)/jump[here][i];
pq.push({-dijk[j], j});
if((*lower_bound(jump[j].begin(), jump[j].end(), jump[here][i]))==jump[here][i])break;
}
}
}
}
}
int main()
{
scanf("%d %d", &n, &m);
for(int i=1; i<=m; i++){
scanf("%d %d", &b[i], &p[i]);
jump[b[i]].pb(p[i]);
}
for(int i=0; i<n; i++){
sort(jump[i].begin(), jump[i].end());
jump[i].erase(unique(jump[i].begin(), jump[i].end()), jump[i].end());
}
fill(dijk, dijk+30005, inf);
dijkstra(b[1]);
printf("%d", dijk[b[2]]==inf?-1:dijk[b[2]]);
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |