Submission #16659

# Submission time Handle Problem Language Result Execution time Memory
16659 2015-09-03T10:57:33 Z eaststar Jakarta Skyscrapers (APIO15_skyscraper) C++14
0 / 100
1000 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,k,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(j=st[p.s];a[j].f==p.s;++j){
            d=p.f;
            for(k=p.s+a[j].s;k<n;k+=a[j].s)if(D[k]>++d)q.push({D[k]=d,k});
            d=p.f;
            for(k=p.s-a[j].s;k>=0;k-=a[j].s)if(D[k]>++d)q.push({D[k]=d,k});
        }
    }
    printf("%d",D[1]);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2188 KB Output is correct
2 Execution timed out 1000 ms 2184 KB Program timed out
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2188 KB Output is correct
2 Execution timed out 1000 ms 2184 KB Program timed out
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2188 KB Output is correct
2 Execution timed out 1000 ms 2184 KB Program timed out
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2188 KB Output is correct
2 Execution timed out 1000 ms 2184 KB Program timed out
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2188 KB Output is correct
2 Execution timed out 1000 ms 2184 KB Program timed out
3 Halted 0 ms 0 KB -