Submission #16648

# Submission time Handle Problem Language Result Execution time Memory
16648 2015-09-03T00:58:14 Z khsoo01 Jakarta Skyscrapers (APIO15_skyscraper) C++
57 / 100
1000 ms 151892 KB
#include<cstdio>
#include<vector>
#include<queue>
#define INF 0x7fffffff
#define f first
#define s second
using namespace std;
vector<int>cg[50005];
priority_queue<pair<int,int> >pq;
int dist[30005],ed[30005][2];
int n,m,a,b,cur,val,tmp;
bool chk[30005][5005];

int main()
{
    int i,j;
    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++) {
        scanf("%d%d",&ed[i][0],&ed[i][1]);
        if(ed[i][1]>5000 || !chk[ed[i][0]][ed[i][1]])
            cg[ed[i][0]].push_back(ed[i][1]);
        if(ed[i][1]<=5000) chk[ed[i][0]][ed[i][1]]=1;
    }
    for(i=0;i<n;i++) dist[i]=INF;
    dist[ed[0][0]]=0;
    pq.push({0,ed[0][0]});
    while(!pq.empty()) {
        val=-pq.top().first;
        cur=pq.top().second;
        pq.pop();
        if(cur==ed[1][0])break;
        if(dist[cur]!=val) continue;
        for(i=0;i<cg[cur].size();i++) {
            tmp=cg[cur][i];
            for(j=cur+tmp;j<n;j+=tmp) {
                if(dist[j]>dist[cur]+(j-cur)/tmp) {
                    dist[j]=dist[cur]+(j-cur)/tmp;
                    pq.push({-dist[j],j});
                }
            }
            for(j=cur-tmp;j>=0;j-=tmp) {
                if(dist[j]>dist[cur]+(cur-j)/tmp) {
                    dist[j]=dist[cur]+(cur-j)/tmp;
                    pq.push({-dist[j],j});
                }
            }
        }
    }
    printf("%d",dist[ed[1][0]]==INF?-1:dist[ed[1][0]]);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 149760 KB Output is correct
2 Correct 0 ms 149760 KB Output is correct
3 Correct 1 ms 149760 KB Output is correct
4 Correct 0 ms 149760 KB Output is correct
5 Correct 0 ms 149760 KB Output is correct
6 Correct 0 ms 149760 KB Output is correct
7 Correct 0 ms 149760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 149760 KB Output is correct
2 Correct 0 ms 149760 KB Output is correct
3 Correct 0 ms 149760 KB Output is correct
4 Correct 0 ms 149760 KB Output is correct
5 Correct 0 ms 149760 KB Output is correct
6 Correct 0 ms 149760 KB Output is correct
7 Correct 0 ms 149760 KB Output is correct
8 Correct 0 ms 149760 KB Output is correct
9 Correct 0 ms 149760 KB Output is correct
10 Correct 0 ms 149760 KB Output is correct
11 Correct 0 ms 149760 KB Output is correct
12 Correct 0 ms 149760 KB Output is correct
13 Correct 0 ms 149760 KB Output is correct
14 Correct 0 ms 149760 KB Output is correct
15 Correct 0 ms 149760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 149760 KB Output is correct
2 Correct 0 ms 149760 KB Output is correct
3 Correct 0 ms 149760 KB Output is correct
4 Correct 0 ms 149760 KB Output is correct
5 Correct 0 ms 149760 KB Output is correct
6 Correct 0 ms 149760 KB Output is correct
7 Correct 0 ms 149760 KB Output is correct
8 Correct 0 ms 149760 KB Output is correct
9 Correct 0 ms 149760 KB Output is correct
10 Correct 0 ms 149760 KB Output is correct
11 Correct 0 ms 149760 KB Output is correct
12 Correct 0 ms 149760 KB Output is correct
13 Correct 0 ms 149760 KB Output is correct
14 Correct 0 ms 149760 KB Output is correct
15 Correct 0 ms 149760 KB Output is correct
16 Correct 0 ms 149760 KB Output is correct
17 Correct 3 ms 149760 KB Output is correct
18 Correct 0 ms 149760 KB Output is correct
19 Correct 0 ms 149760 KB Output is correct
20 Correct 24 ms 149760 KB Output is correct
21 Correct 0 ms 149760 KB Output is correct
22 Correct 0 ms 149760 KB Output is correct
23 Correct 3 ms 149760 KB Output is correct
24 Correct 4 ms 149760 KB Output is correct
25 Correct 0 ms 149760 KB Output is correct
26 Correct 0 ms 149760 KB Output is correct
27 Correct 0 ms 149760 KB Output is correct
28 Correct 0 ms 149760 KB Output is correct
29 Correct 0 ms 149896 KB Output is correct
30 Correct 0 ms 149892 KB Output is correct
31 Correct 0 ms 149896 KB Output is correct
32 Correct 2 ms 149896 KB Output is correct
33 Correct 4 ms 149904 KB Output is correct
34 Correct 3 ms 149904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 149760 KB Output is correct
2 Correct 0 ms 149760 KB Output is correct
3 Correct 0 ms 149760 KB Output is correct
4 Correct 0 ms 149760 KB Output is correct
5 Correct 0 ms 149760 KB Output is correct
6 Correct 0 ms 149760 KB Output is correct
7 Correct 0 ms 149760 KB Output is correct
8 Correct 0 ms 149760 KB Output is correct
9 Correct 0 ms 149760 KB Output is correct
10 Correct 0 ms 149760 KB Output is correct
11 Correct 0 ms 149760 KB Output is correct
12 Correct 0 ms 149760 KB Output is correct
13 Correct 0 ms 149760 KB Output is correct
14 Correct 1 ms 149760 KB Output is correct
15 Correct 1 ms 149760 KB Output is correct
16 Correct 0 ms 149760 KB Output is correct
17 Correct 0 ms 149760 KB Output is correct
18 Correct 0 ms 149760 KB Output is correct
19 Correct 0 ms 149760 KB Output is correct
20 Correct 24 ms 149760 KB Output is correct
21 Correct 0 ms 149760 KB Output is correct
22 Correct 0 ms 149760 KB Output is correct
23 Correct 3 ms 149760 KB Output is correct
24 Correct 0 ms 149760 KB Output is correct
25 Correct 0 ms 149760 KB Output is correct
26 Correct 0 ms 149760 KB Output is correct
27 Correct 0 ms 149760 KB Output is correct
28 Correct 3 ms 149760 KB Output is correct
29 Correct 0 ms 149896 KB Output is correct
30 Correct 2 ms 149892 KB Output is correct
31 Correct 2 ms 149896 KB Output is correct
32 Correct 0 ms 149896 KB Output is correct
33 Correct 4 ms 149904 KB Output is correct
34 Correct 0 ms 149904 KB Output is correct
35 Correct 11 ms 150024 KB Output is correct
36 Correct 0 ms 149760 KB Output is correct
37 Correct 3 ms 150060 KB Output is correct
38 Correct 11 ms 150024 KB Output is correct
39 Correct 11 ms 150024 KB Output is correct
40 Correct 5 ms 150024 KB Output is correct
41 Correct 14 ms 150024 KB Output is correct
42 Correct 6 ms 149760 KB Output is correct
43 Correct 8 ms 149760 KB Output is correct
44 Correct 27 ms 149760 KB Output is correct
45 Correct 12 ms 150068 KB Output is correct
46 Correct 13 ms 150064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 149760 KB Output is correct
2 Correct 0 ms 149760 KB Output is correct
3 Correct 0 ms 149760 KB Output is correct
4 Correct 0 ms 149760 KB Output is correct
5 Correct 0 ms 149760 KB Output is correct
6 Correct 0 ms 149760 KB Output is correct
7 Correct 0 ms 149760 KB Output is correct
8 Correct 0 ms 149760 KB Output is correct
9 Correct 0 ms 149760 KB Output is correct
10 Correct 0 ms 149760 KB Output is correct
11 Correct 0 ms 149760 KB Output is correct
12 Correct 0 ms 149760 KB Output is correct
13 Correct 2 ms 149760 KB Output is correct
14 Correct 1 ms 149760 KB Output is correct
15 Correct 1 ms 149760 KB Output is correct
16 Correct 0 ms 149760 KB Output is correct
17 Correct 0 ms 149760 KB Output is correct
18 Correct 0 ms 149760 KB Output is correct
19 Correct 0 ms 149760 KB Output is correct
20 Correct 20 ms 149760 KB Output is correct
21 Correct 0 ms 149760 KB Output is correct
22 Correct 0 ms 149760 KB Output is correct
23 Correct 3 ms 149760 KB Output is correct
24 Correct 0 ms 149760 KB Output is correct
25 Correct 3 ms 149760 KB Output is correct
26 Correct 0 ms 149760 KB Output is correct
27 Correct 0 ms 149760 KB Output is correct
28 Correct 0 ms 149760 KB Output is correct
29 Correct 3 ms 149896 KB Output is correct
30 Correct 0 ms 149892 KB Output is correct
31 Correct 0 ms 149896 KB Output is correct
32 Correct 1 ms 149896 KB Output is correct
33 Correct 0 ms 149904 KB Output is correct
34 Correct 0 ms 149904 KB Output is correct
35 Correct 7 ms 150024 KB Output is correct
36 Correct 0 ms 149760 KB Output is correct
37 Correct 12 ms 150060 KB Output is correct
38 Correct 5 ms 150024 KB Output is correct
39 Correct 0 ms 150024 KB Output is correct
40 Correct 0 ms 150024 KB Output is correct
41 Correct 8 ms 150024 KB Output is correct
42 Correct 0 ms 149760 KB Output is correct
43 Correct 0 ms 149760 KB Output is correct
44 Correct 24 ms 149760 KB Output is correct
45 Correct 7 ms 150068 KB Output is correct
46 Correct 7 ms 150064 KB Output is correct
47 Correct 11 ms 150876 KB Output is correct
48 Correct 13 ms 150156 KB Output is correct
49 Correct 10 ms 150156 KB Output is correct
50 Correct 4 ms 150024 KB Output is correct
51 Correct 28 ms 151892 KB Output is correct
52 Correct 26 ms 151128 KB Output is correct
53 Correct 15 ms 150548 KB Output is correct
54 Correct 3 ms 149892 KB Output is correct
55 Correct 3 ms 149892 KB Output is correct
56 Execution timed out 1000 ms 151084 KB Program timed out
57 Halted 0 ms 0 KB -