답안 #16660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
16660 2015-09-03T11:01:27 Z eaststar Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
0 ms 2188 KB
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> data;
data a[30010];
int st[30010],D[30010];
priority_queue<data,vector<data>,greater<data> > q;
int main(){
    int i,j,n,m,d;
    scanf("%d%d",&n,&m);
    for(i=0;i<m;++i)scanf("%d%d",&a[i].f,&a[i].s);
    sort(a,a+m);
    st[a[0].f]=0;
    for(i=1;i<m;++i)if(a[i].f!=a[i-1].f)st[a[i].f]=i;
    for(i=1;i<n;++i)D[i]=2e9;
    q.push({0,a[0].f});
    while(!q.empty()){
        data p=q.top();
        q.pop();
        if(D[p.s]!=p.f)continue;
        for(i=st[p.s];a[i].f==p.s&&i<m;++i){
            d=p.f;
            for(j=p.s+a[i].s;j<n;j+=a[i].s)if(D[j]>++d)q.push({D[j]=d,j});
            d=p.f;
            for(j=p.s-a[i].s;j>=0;j-=a[i].s)if(D[j]>++d)q.push({D[j]=d,j});
        }
    }
    printf("%d",D[1]);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2188 KB Output is correct
2 Correct 0 ms 2188 KB Output is correct
3 Incorrect 0 ms 2188 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2188 KB Output is correct
2 Correct 0 ms 2188 KB Output is correct
3 Incorrect 0 ms 2188 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2188 KB Output is correct
2 Correct 0 ms 2188 KB Output is correct
3 Incorrect 0 ms 2188 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2188 KB Output is correct
2 Correct 0 ms 2188 KB Output is correct
3 Incorrect 0 ms 2188 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2188 KB Output is correct
2 Correct 0 ms 2188 KB Output is correct
3 Incorrect 0 ms 2188 KB Output isn't correct
4 Halted 0 ms 0 KB -