# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
219991 | MKopchev | Jakarta Skyscrapers (APIO15_skyscraper) | C++14 | 110 ms | 5624 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int nmax=3e4+42;
int dist[nmax];
set<int> seen[nmax];
int m,n;
int wanted;
bool been[nmax];
priority_queue< pair<int/*dist*/,int/*node*/> > pq;
bool in(int where,int val)
{
return seen[where].count(val);
}
int main()
{
scanf("%i%i",&m,&n);
for(int i=0;i<m;i++)dist[i]=1e9;
int b,p;
for(int i=0;i<n;i++)
{
scanf("%i%i",&b,&p);
if(i==0){dist[b]=0;pq.push({0,b});}
if(i==1)wanted=b;
seen[b].insert(p);
}
while(pq.size())
{
pair<int/*dist*/,int/*node*/> current=pq.top();
pq.pop();
if(been[current.second])continue;
been[current.second]=1;
current.first=-current.first;
if(current.second==wanted)
{
printf("%i\n",current.first);
exit(0);
}
for(auto dog:seen[current.second])
{
for(int i=current.second+dog;i<m;i+=dog)
{
int dist_now=current.first+(i-current.second)/dog;
if(dist[i]>dist_now)
{
dist[i]=dist_now;
pq.push({-dist_now,i});
}
if(in(i,dog))break;
}
for(int i=current.second-dog;i>=0;i-=dog)
{
int dist_now=current.first+(current.second-i)/dog;
if(dist[i]>dist_now)
{
dist[i]=dist_now;
pq.push({-dist_now,i});
}
if(in(i,dog))break;
}
}
}
printf("-1\n");
return 0;
}
컴파일 시 표준 에러 (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... |