# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
874607 | h4d1 | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 1006 ms | 1108 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int inf = 2e9;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, m;
scanf("%d%d", &n, &m);
pair<int, int> a[m];
for(int i = 0; i < m; i++)
{
scanf("%d%d", &a[i].first, &a[i].second);
}
int s = a[0].first, t = a[1].first, adj[n];
fill(adj, adj+n, m);
sort(a, a+m);
for(int i = 0; i < m; i++)
{
if(!i)
{
adj[a[i].first] = i;
}
else if(a[i].first != a[i-1].first)
{
adj[a[i].first] = i;
}
}
int d[n];
fill(d, d+n, inf);
priority_queue<pair<int, int>> pq;
pq.push({d[s]=0, s});
while(pq.size())
{
int v = pq.top().second;
pq.pop();
for(int i = adj[v]; ((i < m)&&(a[i].first == v)); i++)
{
int j = a[i].second, x = 0;
while((v+(x*j) < n) || (v-(x*j) >= 0))
{
if((v+(x*j) < n) && (d[v+(x*j)] > d[v]+x))
{
pq.push({d[v+(x*j)] = d[v]+x, v+(x*j)});
}
if((v-(x*j) >= 0) && (d[v-(x*j)] > d[v]+x))
{
pq.push({d[v-(x*j)] = d[v]+x, v-(x*j)});
}
x++;
}
}
}
printf("%d\n", d[t] != 2e9 ? d[t] : -1);
}
컴파일 시 표준 에러 (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... |