답안 #14735

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14735 2015-06-15T11:56:28 Z gs13068 Jakarta Skyscrapers (APIO15_skyscraper) C++
100 / 100
93 ms 49496 KB
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>

int p[33333];
int q[33333];
std::vector<int> a[33333];
std::priority_queue<std::pair<int,int> > pq;
int t[33333][333];
int d[33333];
int v[33333];

int main()
{
	std::pair<int,int> tt;
	int i,j,k,l,n,m;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++)
	{
		scanf("%d%d",&p[i],&q[i]);
		if(q[i]>=300||!t[p[i]][q[i]])a[p[i]].push_back(q[i]);
        if(q[i]<300)t[p[i]][q[i]]=1;
	}
	for(i=0;i<n;i++)d[i]=1e9;
	pq.push(std::make_pair(0,p[0]));
    while(!pq.empty()&&!v[p[1]])
    {
		tt=pq.top();
		pq.pop();
		if(v[tt.second])continue;
        v[tt.second]=1;
        d[tt.second]=-tt.first;
        k=tt.second;
        for(j=0;j<a[k].size();j++)
        {
			for(l=1;k+l*a[k][j]<n;l++)
			{
				if(!v[k+l*a[k][j]]&&d[k+l*a[k][j]]>d[k]+l)
				{
					d[k+l*a[k][j]]=d[k]+l;
                    pq.push(std::make_pair(-d[k+l*a[k][j]],k+l*a[k][j]));
				}
				if(a[k][j]<300&&t[k+l*a[k][j]][a[k][j]])break;
			}
			for(l=1;k-l*a[k][j]>=0;l++)
			{
				if(!v[k-l*a[k][j]]&&d[k-l*a[k][j]]>d[k]+l)
				{
					d[k-l*a[k][j]]=d[k]+l;
                    pq.push(std::make_pair(-d[k-l*a[k][j]],k-l*a[k][j]));
				}
				if(a[k][j]<300&&t[k-l*a[k][j]][a[k][j]])break;
			}
        }
    }
    if(!v[p[1]])puts("-1");
    else printf("%d\n",d[p[1]]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 46240 KB Output is correct
2 Correct 0 ms 46240 KB Output is correct
3 Correct 0 ms 46240 KB Output is correct
4 Correct 0 ms 46240 KB Output is correct
5 Correct 0 ms 46240 KB Output is correct
6 Correct 0 ms 46240 KB Output is correct
7 Correct 0 ms 46240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 46240 KB Output is correct
2 Correct 0 ms 46240 KB Output is correct
3 Correct 0 ms 46240 KB Output is correct
4 Correct 0 ms 46240 KB Output is correct
5 Correct 0 ms 46240 KB Output is correct
6 Correct 0 ms 46240 KB Output is correct
7 Correct 0 ms 46240 KB Output is correct
8 Correct 0 ms 46240 KB Output is correct
9 Correct 0 ms 46240 KB Output is correct
10 Correct 0 ms 46240 KB Output is correct
11 Correct 0 ms 46240 KB Output is correct
12 Correct 0 ms 46240 KB Output is correct
13 Correct 0 ms 46240 KB Output is correct
14 Correct 0 ms 46240 KB Output is correct
15 Correct 0 ms 46240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 46240 KB Output is correct
2 Correct 0 ms 46240 KB Output is correct
3 Correct 0 ms 46240 KB Output is correct
4 Correct 0 ms 46240 KB Output is correct
5 Correct 0 ms 46240 KB Output is correct
6 Correct 0 ms 46240 KB Output is correct
7 Correct 0 ms 46240 KB Output is correct
8 Correct 0 ms 46240 KB Output is correct
9 Correct 0 ms 46240 KB Output is correct
10 Correct 0 ms 46240 KB Output is correct
11 Correct 0 ms 46240 KB Output is correct
12 Correct 0 ms 46240 KB Output is correct
13 Correct 0 ms 46240 KB Output is correct
14 Correct 0 ms 46240 KB Output is correct
15 Correct 0 ms 46240 KB Output is correct
16 Correct 0 ms 46240 KB Output is correct
17 Correct 0 ms 46240 KB Output is correct
18 Correct 0 ms 46240 KB Output is correct
19 Correct 0 ms 46240 KB Output is correct
20 Correct 0 ms 46240 KB Output is correct
21 Correct 0 ms 46240 KB Output is correct
22 Correct 0 ms 46240 KB Output is correct
23 Correct 2 ms 46240 KB Output is correct
24 Correct 0 ms 46240 KB Output is correct
25 Correct 0 ms 46240 KB Output is correct
26 Correct 1 ms 46240 KB Output is correct
27 Correct 2 ms 46240 KB Output is correct
28 Correct 2 ms 46240 KB Output is correct
29 Correct 3 ms 46376 KB Output is correct
30 Correct 0 ms 46240 KB Output is correct
31 Correct 0 ms 46376 KB Output is correct
32 Correct 1 ms 46376 KB Output is correct
33 Correct 0 ms 46384 KB Output is correct
34 Correct 0 ms 46384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 46240 KB Output is correct
2 Correct 0 ms 46240 KB Output is correct
3 Correct 0 ms 46240 KB Output is correct
4 Correct 0 ms 46240 KB Output is correct
5 Correct 0 ms 46240 KB Output is correct
6 Correct 0 ms 46240 KB Output is correct
7 Correct 0 ms 46240 KB Output is correct
8 Correct 0 ms 46240 KB Output is correct
9 Correct 0 ms 46240 KB Output is correct
10 Correct 0 ms 46240 KB Output is correct
11 Correct 0 ms 46240 KB Output is correct
12 Correct 1 ms 46240 KB Output is correct
13 Correct 1 ms 46240 KB Output is correct
14 Correct 1 ms 46240 KB Output is correct
15 Correct 0 ms 46240 KB Output is correct
16 Correct 0 ms 46240 KB Output is correct
17 Correct 2 ms 46240 KB Output is correct
18 Correct 0 ms 46240 KB Output is correct
19 Correct 1 ms 46240 KB Output is correct
20 Correct 2 ms 46240 KB Output is correct
21 Correct 0 ms 46240 KB Output is correct
22 Correct 0 ms 46240 KB Output is correct
23 Correct 0 ms 46240 KB Output is correct
24 Correct 3 ms 46240 KB Output is correct
25 Correct 0 ms 46240 KB Output is correct
26 Correct 0 ms 46240 KB Output is correct
27 Correct 0 ms 46240 KB Output is correct
28 Correct 0 ms 46240 KB Output is correct
29 Correct 3 ms 46376 KB Output is correct
30 Correct 2 ms 46240 KB Output is correct
31 Correct 0 ms 46376 KB Output is correct
32 Correct 0 ms 46376 KB Output is correct
33 Correct 4 ms 46384 KB Output is correct
34 Correct 0 ms 46384 KB Output is correct
35 Correct 11 ms 46504 KB Output is correct
36 Correct 0 ms 46240 KB Output is correct
37 Correct 10 ms 46540 KB Output is correct
38 Correct 7 ms 46504 KB Output is correct
39 Correct 0 ms 46504 KB Output is correct
40 Correct 12 ms 46508 KB Output is correct
41 Correct 12 ms 46504 KB Output is correct
42 Correct 5 ms 46240 KB Output is correct
43 Correct 6 ms 46240 KB Output is correct
44 Correct 9 ms 46240 KB Output is correct
45 Correct 14 ms 46548 KB Output is correct
46 Correct 11 ms 46544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 46240 KB Output is correct
2 Correct 0 ms 46240 KB Output is correct
3 Correct 0 ms 46240 KB Output is correct
4 Correct 0 ms 46240 KB Output is correct
5 Correct 0 ms 46240 KB Output is correct
6 Correct 0 ms 46240 KB Output is correct
7 Correct 1 ms 46240 KB Output is correct
8 Correct 0 ms 46240 KB Output is correct
9 Correct 0 ms 46240 KB Output is correct
10 Correct 0 ms 46240 KB Output is correct
11 Correct 0 ms 46240 KB Output is correct
12 Correct 0 ms 46240 KB Output is correct
13 Correct 0 ms 46240 KB Output is correct
14 Correct 0 ms 46240 KB Output is correct
15 Correct 0 ms 46240 KB Output is correct
16 Correct 0 ms 46240 KB Output is correct
17 Correct 3 ms 46240 KB Output is correct
18 Correct 2 ms 46240 KB Output is correct
19 Correct 0 ms 46240 KB Output is correct
20 Correct 0 ms 46240 KB Output is correct
21 Correct 1 ms 46240 KB Output is correct
22 Correct 0 ms 46240 KB Output is correct
23 Correct 0 ms 46240 KB Output is correct
24 Correct 0 ms 46240 KB Output is correct
25 Correct 2 ms 46240 KB Output is correct
26 Correct 0 ms 46240 KB Output is correct
27 Correct 0 ms 46240 KB Output is correct
28 Correct 0 ms 46240 KB Output is correct
29 Correct 0 ms 46376 KB Output is correct
30 Correct 0 ms 46240 KB Output is correct
31 Correct 0 ms 46376 KB Output is correct
32 Correct 0 ms 46376 KB Output is correct
33 Correct 0 ms 46384 KB Output is correct
34 Correct 1 ms 46384 KB Output is correct
35 Correct 11 ms 46504 KB Output is correct
36 Correct 2 ms 46240 KB Output is correct
37 Correct 7 ms 46540 KB Output is correct
38 Correct 14 ms 46504 KB Output is correct
39 Correct 9 ms 46504 KB Output is correct
40 Correct 12 ms 46508 KB Output is correct
41 Correct 5 ms 46504 KB Output is correct
42 Correct 0 ms 46240 KB Output is correct
43 Correct 6 ms 46240 KB Output is correct
44 Correct 7 ms 46240 KB Output is correct
45 Correct 10 ms 46548 KB Output is correct
46 Correct 13 ms 46544 KB Output is correct
47 Correct 15 ms 46972 KB Output is correct
48 Correct 5 ms 46636 KB Output is correct
49 Correct 10 ms 46636 KB Output is correct
50 Correct 7 ms 46504 KB Output is correct
51 Correct 23 ms 47604 KB Output is correct
52 Correct 24 ms 47608 KB Output is correct
53 Correct 13 ms 47224 KB Output is correct
54 Correct 0 ms 46372 KB Output is correct
55 Correct 0 ms 46372 KB Output is correct
56 Correct 14 ms 47164 KB Output is correct
57 Correct 3 ms 46700 KB Output is correct
58 Correct 12 ms 46372 KB Output is correct
59 Correct 10 ms 46372 KB Output is correct
60 Correct 7 ms 46376 KB Output is correct
61 Correct 4 ms 46396 KB Output is correct
62 Correct 19 ms 47164 KB Output is correct
63 Correct 36 ms 48020 KB Output is correct
64 Correct 37 ms 47980 KB Output is correct
65 Correct 52 ms 47992 KB Output is correct
66 Correct 93 ms 49492 KB Output is correct
67 Correct 78 ms 49496 KB Output is correct