Submission #14449

# Submission time Handle Problem Language Result Execution time Memory
14449 2015-05-17T04:06:34 Z dohyun0324 Jakarta Skyscrapers (APIO15_skyscraper) C++
57 / 100
1000 ms 3028 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>v[30010];
int k,top,arr[30010],pos,n,m,d[30010],now,c,ch[30010],mini;
struct data
{
    int x,p;
}a[30010];
int min(int x,int y)
{
    if(x>y) return y;
    return x;
}
int main()
{
    int i,j;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++) ch[i]=1;
    for(i=0;i<m;i++)
    {
        scanf("%d %d",&a[i].x,&a[i].p);
        v[a[i].x].push_back(i);
        ch[a[i].x]=0;
    }
    for(i=0;i<n;i++) d[i]=2147483647;
    d[a[0].x]=0;
    now=a[0].x;
    top=0; k=v[now].size();
    for(i=0;i<k;i++) arr[++top]=a[v[now][i]].p;
    arr[0]=-1;
    while(1)
    {
        ch[now]=1;
        for(i=1;i<=top;i++)
        {
            if(arr[i]==arr[i-1]) continue;
            c=0;
            for(j=now;j<n;j+=arr[i])
            {
                d[j]=min(d[j],d[now]+c);
                c++;
            }
            c=0;
            for(j=now;j>=0;j-=arr[i])
            {
                d[j]=min(d[j],d[now]+c);
                c++;
            }
        }
        mini=2147483647; pos=-1;
        for(i=0;i<n;i++)
        {
            if(mini>d[i] && ch[i]==0) mini=d[i], pos=i;
        }
        if(pos==-1) break;
        top=0; k=v[pos].size();
        for(i=0;i<k;i++) arr[++top]=a[v[pos][i]].p;
        now=pos;
        if(now==a[1].x) break;
    }
    if(d[a[1].x]==2147483647) printf("-1\n");
    else printf("%d\n",d[a[1].x]);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2500 KB Output is correct
2 Correct 0 ms 2500 KB Output is correct
3 Correct 0 ms 2500 KB Output is correct
4 Correct 0 ms 2500 KB Output is correct
5 Correct 0 ms 2500 KB Output is correct
6 Correct 0 ms 2500 KB Output is correct
7 Correct 0 ms 2500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2500 KB Output is correct
2 Correct 0 ms 2500 KB Output is correct
3 Correct 0 ms 2500 KB Output is correct
4 Correct 0 ms 2500 KB Output is correct
5 Correct 0 ms 2500 KB Output is correct
6 Correct 0 ms 2500 KB Output is correct
7 Correct 0 ms 2500 KB Output is correct
8 Correct 0 ms 2500 KB Output is correct
9 Correct 0 ms 2500 KB Output is correct
10 Correct 0 ms 2500 KB Output is correct
11 Correct 0 ms 2500 KB Output is correct
12 Correct 0 ms 2500 KB Output is correct
13 Correct 0 ms 2500 KB Output is correct
14 Correct 0 ms 2500 KB Output is correct
15 Correct 0 ms 2500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2500 KB Output is correct
2 Correct 0 ms 2500 KB Output is correct
3 Correct 0 ms 2500 KB Output is correct
4 Correct 0 ms 2500 KB Output is correct
5 Correct 0 ms 2500 KB Output is correct
6 Correct 0 ms 2500 KB Output is correct
7 Correct 0 ms 2500 KB Output is correct
8 Correct 0 ms 2500 KB Output is correct
9 Correct 0 ms 2500 KB Output is correct
10 Correct 1 ms 2500 KB Output is correct
11 Correct 0 ms 2500 KB Output is correct
12 Correct 0 ms 2500 KB Output is correct
13 Correct 0 ms 2500 KB Output is correct
14 Correct 0 ms 2500 KB Output is correct
15 Correct 0 ms 2500 KB Output is correct
16 Correct 0 ms 2500 KB Output is correct
17 Correct 0 ms 2500 KB Output is correct
18 Correct 0 ms 2500 KB Output is correct
19 Correct 0 ms 2500 KB Output is correct
20 Correct 15 ms 2500 KB Output is correct
21 Correct 0 ms 2500 KB Output is correct
22 Correct 0 ms 2500 KB Output is correct
23 Correct 4 ms 2500 KB Output is correct
24 Correct 3 ms 2500 KB Output is correct
25 Correct 1 ms 2500 KB Output is correct
26 Correct 0 ms 2500 KB Output is correct
27 Correct 1 ms 2500 KB Output is correct
28 Correct 9 ms 2500 KB Output is correct
29 Correct 1 ms 2500 KB Output is correct
30 Correct 0 ms 2500 KB Output is correct
31 Correct 0 ms 2500 KB Output is correct
32 Correct 0 ms 2500 KB Output is correct
33 Correct 0 ms 2500 KB Output is correct
34 Correct 0 ms 2500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2500 KB Output is correct
2 Correct 0 ms 2500 KB Output is correct
3 Correct 0 ms 2500 KB Output is correct
4 Correct 0 ms 2500 KB Output is correct
5 Correct 0 ms 2500 KB Output is correct
6 Correct 0 ms 2500 KB Output is correct
7 Correct 0 ms 2500 KB Output is correct
8 Correct 0 ms 2500 KB Output is correct
9 Correct 0 ms 2500 KB Output is correct
10 Correct 0 ms 2500 KB Output is correct
11 Correct 0 ms 2500 KB Output is correct
12 Correct 0 ms 2500 KB Output is correct
13 Correct 0 ms 2500 KB Output is correct
14 Correct 1 ms 2500 KB Output is correct
15 Correct 0 ms 2500 KB Output is correct
16 Correct 0 ms 2500 KB Output is correct
17 Correct 2 ms 2500 KB Output is correct
18 Correct 0 ms 2500 KB Output is correct
19 Correct 0 ms 2500 KB Output is correct
20 Correct 14 ms 2500 KB Output is correct
21 Correct 1 ms 2500 KB Output is correct
22 Correct 0 ms 2500 KB Output is correct
23 Correct 4 ms 2500 KB Output is correct
24 Correct 6 ms 2500 KB Output is correct
25 Correct 2 ms 2500 KB Output is correct
26 Correct 1 ms 2500 KB Output is correct
27 Correct 0 ms 2500 KB Output is correct
28 Correct 9 ms 2500 KB Output is correct
29 Correct 0 ms 2500 KB Output is correct
30 Correct 0 ms 2500 KB Output is correct
31 Correct 1 ms 2500 KB Output is correct
32 Correct 0 ms 2500 KB Output is correct
33 Correct 0 ms 2500 KB Output is correct
34 Correct 2 ms 2500 KB Output is correct
35 Correct 14 ms 2632 KB Output is correct
36 Correct 0 ms 2500 KB Output is correct
37 Correct 9 ms 2632 KB Output is correct
38 Correct 14 ms 2632 KB Output is correct
39 Correct 9 ms 2632 KB Output is correct
40 Correct 11 ms 2632 KB Output is correct
41 Correct 0 ms 2632 KB Output is correct
42 Correct 0 ms 2632 KB Output is correct
43 Correct 4 ms 2632 KB Output is correct
44 Correct 22 ms 2632 KB Output is correct
45 Correct 4 ms 2632 KB Output is correct
46 Correct 11 ms 2632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2500 KB Output is correct
2 Correct 0 ms 2500 KB Output is correct
3 Correct 0 ms 2500 KB Output is correct
4 Correct 0 ms 2500 KB Output is correct
5 Correct 0 ms 2500 KB Output is correct
6 Correct 0 ms 2500 KB Output is correct
7 Correct 0 ms 2500 KB Output is correct
8 Correct 0 ms 2500 KB Output is correct
9 Correct 0 ms 2500 KB Output is correct
10 Correct 0 ms 2500 KB Output is correct
11 Correct 0 ms 2500 KB Output is correct
12 Correct 1 ms 2500 KB Output is correct
13 Correct 0 ms 2500 KB Output is correct
14 Correct 0 ms 2500 KB Output is correct
15 Correct 0 ms 2500 KB Output is correct
16 Correct 0 ms 2500 KB Output is correct
17 Correct 2 ms 2500 KB Output is correct
18 Correct 0 ms 2500 KB Output is correct
19 Correct 0 ms 2500 KB Output is correct
20 Correct 14 ms 2500 KB Output is correct
21 Correct 0 ms 2500 KB Output is correct
22 Correct 0 ms 2500 KB Output is correct
23 Correct 4 ms 2500 KB Output is correct
24 Correct 6 ms 2500 KB Output is correct
25 Correct 0 ms 2500 KB Output is correct
26 Correct 0 ms 2500 KB Output is correct
27 Correct 0 ms 2500 KB Output is correct
28 Correct 9 ms 2500 KB Output is correct
29 Correct 0 ms 2500 KB Output is correct
30 Correct 0 ms 2500 KB Output is correct
31 Correct 1 ms 2500 KB Output is correct
32 Correct 0 ms 2500 KB Output is correct
33 Correct 0 ms 2500 KB Output is correct
34 Correct 0 ms 2500 KB Output is correct
35 Correct 7 ms 2632 KB Output is correct
36 Correct 0 ms 2500 KB Output is correct
37 Correct 13 ms 2632 KB Output is correct
38 Correct 7 ms 2632 KB Output is correct
39 Correct 0 ms 2632 KB Output is correct
40 Correct 0 ms 2632 KB Output is correct
41 Correct 13 ms 2632 KB Output is correct
42 Correct 0 ms 2632 KB Output is correct
43 Correct 0 ms 2632 KB Output is correct
44 Correct 23 ms 2632 KB Output is correct
45 Correct 0 ms 2632 KB Output is correct
46 Correct 0 ms 2632 KB Output is correct
47 Correct 179 ms 2764 KB Output is correct
48 Correct 0 ms 2896 KB Output is correct
49 Correct 7 ms 2896 KB Output is correct
50 Correct 0 ms 2764 KB Output is correct
51 Execution timed out 1000 ms 3028 KB Program timed out
52 Halted 0 ms 0 KB -