답안 #116522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116522 2019-06-12T16:42:19 Z roseanne_pcy Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
643 ms 74664 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
 
const int maxn = 3e4+5;
const int half = 173;
 
int n, m;
int dist[maxn*180*2];

vector< ii > adj[maxn];
 
bool ok(int x)
{
	return 0<= x && x< n;
}

int N;

priority_queue< pair<int, int> > q;

int conv(int u, int md, int isleft)
{
	if(isleft) return (half+1)*n+(md-1)*n+u;
	return md*n+u;
}

void bfs(int s)
{
	for(int i = 0; i< N; i++) dist[i] = 1e9;
	dist[s] = 0; q.push({0, s});
	while(!q.empty())
	{
		auto kk = q.top(); q.pop();
		int u = kk.Y, d = -kk.X;
		// printf("%d\n", u);
		if(d> dist[u]) continue;
		if(u< n)
		{
			for(auto k2 : adj[u])
			{
				int v = k2.X, w = k2.Y;
				if(dist[v]> dist[u]+w)
				{
					dist[v] = dist[u]+w;
					q.push({-dist[v], v});
				}
			}
		}
		if(u>= n)
		{
			bool isleft = false;
			int tmp;
			if(u< (half+1)*n)
			{		
				isleft = false;
				tmp = u-n;
			}
			else
			{
				isleft = true;
				tmp = u-(half+1)*n;
			}
			int md = tmp/n+1;
			int sub = tmp%n;
			// assert(conv(sub, md, isleft) == u);
			if(isleft && ok(sub-md))
			{
				int nxt = conv(sub-md, md, isleft);
				if(dist[nxt]> dist[u]+1)
				{
					dist[nxt] = dist[u]+1;
					q.push({-dist[nxt], nxt});
				}
				if(dist[sub-md]> dist[u]+1)
				{
					dist[sub-md] = dist[u]+1;
					q.push({-dist[sub-md], sub-md});
				}
			}
			if(!isleft && ok(sub+md))
			{
				int nxt = conv(sub+md, md, isleft);
				if(dist[nxt]> dist[u]+1)
				{
					dist[nxt] = dist[u]+1;
					q.push({-dist[nxt], nxt});
				}
				if(dist[sub+md]> dist[u]+1)
				{
					dist[sub+md] = dist[u]+1;
					q.push({-dist[sub+md], sub+md});
				}
			}
		}
	}
}
 
int hom[maxn], mana[maxn];
 
int main()
{
	scanf("%d %d", &n, &m);
	N = conv(n-1, half, 1);
	for(int i = 0; i< m; i++)
	{
		scanf("%d %d", &hom[i], &mana[i]);
	}
	// printf("okay\n");
	for(int i = 0; i< m; i++)
	{
		int pw = mana[i];
		if(pw> half)
		{
			int cur = hom[i]+pw;
			while(cur< n)
			{
				adj[hom[i]].pb({cur, abs(cur-hom[i])/pw});
				cur += pw;
			}
			cur = hom[i]-pw;
			while(cur>= 0)
			{
				adj[hom[i]].pb({cur, abs(cur-hom[i])/pw});
				cur -= pw;
			}
		}
		else
		{
			int x = hom[i];
			adj[x].pb({conv(x, pw, 0), 0});
			adj[x].pb({conv(x, pw, 1), 0});
		}
	}
	bfs(hom[0]);
	if(dist[hom[1]] == 1e9) printf("-1\n");
	else printf("%d\n", dist[hom[1]]);
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:109:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:113:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &hom[i], &mana[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1024 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 2 ms 1024 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 2 ms 1024 KB Output is correct
7 Correct 2 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1024 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 2 ms 1024 KB Output is correct
4 Correct 3 ms 1152 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 2 ms 1024 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 2 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 3 ms 1280 KB Output is correct
12 Correct 3 ms 1280 KB Output is correct
13 Correct 3 ms 1280 KB Output is correct
14 Correct 4 ms 1280 KB Output is correct
15 Correct 4 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 2 ms 1024 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
8 Correct 2 ms 1152 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 4 ms 1280 KB Output is correct
12 Correct 3 ms 1280 KB Output is correct
13 Correct 3 ms 1280 KB Output is correct
14 Correct 4 ms 1280 KB Output is correct
15 Correct 3 ms 1280 KB Output is correct
16 Correct 3 ms 1280 KB Output is correct
17 Correct 5 ms 2176 KB Output is correct
18 Correct 4 ms 3456 KB Output is correct
19 Correct 5 ms 3840 KB Output is correct
20 Correct 5 ms 3840 KB Output is correct
21 Correct 4 ms 1664 KB Output is correct
22 Correct 5 ms 3456 KB Output is correct
23 Correct 5 ms 3328 KB Output is correct
24 Correct 6 ms 3712 KB Output is correct
25 Correct 5 ms 3840 KB Output is correct
26 Correct 5 ms 3840 KB Output is correct
27 Correct 5 ms 3840 KB Output is correct
28 Correct 5 ms 3840 KB Output is correct
29 Correct 9 ms 3712 KB Output is correct
30 Correct 5 ms 3712 KB Output is correct
31 Correct 7 ms 3840 KB Output is correct
32 Correct 6 ms 3712 KB Output is correct
33 Correct 14 ms 3840 KB Output is correct
34 Correct 14 ms 3868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 2 ms 1024 KB Output is correct
3 Correct 2 ms 1024 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Correct 2 ms 1068 KB Output is correct
6 Correct 3 ms 1024 KB Output is correct
7 Correct 2 ms 1024 KB Output is correct
8 Correct 3 ms 1024 KB Output is correct
9 Correct 3 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 4 ms 1280 KB Output is correct
12 Correct 3 ms 1280 KB Output is correct
13 Correct 3 ms 1280 KB Output is correct
14 Correct 4 ms 1280 KB Output is correct
15 Correct 4 ms 1280 KB Output is correct
16 Correct 3 ms 1280 KB Output is correct
17 Correct 5 ms 2176 KB Output is correct
18 Correct 5 ms 3456 KB Output is correct
19 Correct 5 ms 3712 KB Output is correct
20 Correct 5 ms 3840 KB Output is correct
21 Correct 3 ms 1664 KB Output is correct
22 Correct 4 ms 3456 KB Output is correct
23 Correct 5 ms 3328 KB Output is correct
24 Correct 6 ms 3712 KB Output is correct
25 Correct 5 ms 3840 KB Output is correct
26 Correct 6 ms 3840 KB Output is correct
27 Correct 5 ms 3840 KB Output is correct
28 Correct 6 ms 3756 KB Output is correct
29 Correct 9 ms 3840 KB Output is correct
30 Correct 6 ms 3712 KB Output is correct
31 Correct 7 ms 3840 KB Output is correct
32 Correct 6 ms 3788 KB Output is correct
33 Correct 14 ms 3840 KB Output is correct
34 Correct 14 ms 3840 KB Output is correct
35 Correct 17 ms 3584 KB Output is correct
36 Correct 6 ms 2688 KB Output is correct
37 Correct 24 ms 4736 KB Output is correct
38 Correct 21 ms 4736 KB Output is correct
39 Correct 22 ms 4736 KB Output is correct
40 Correct 22 ms 4736 KB Output is correct
41 Correct 22 ms 4736 KB Output is correct
42 Correct 10 ms 4600 KB Output is correct
43 Correct 10 ms 4728 KB Output is correct
44 Correct 10 ms 4600 KB Output is correct
45 Correct 48 ms 6144 KB Output is correct
46 Correct 48 ms 6088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1024 KB Output is correct
2 Correct 3 ms 1084 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 2 ms 1024 KB Output is correct
7 Correct 2 ms 1024 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 2 ms 1152 KB Output is correct
10 Correct 3 ms 1152 KB Output is correct
11 Correct 4 ms 1280 KB Output is correct
12 Correct 3 ms 1280 KB Output is correct
13 Correct 3 ms 1280 KB Output is correct
14 Correct 4 ms 1280 KB Output is correct
15 Correct 4 ms 1280 KB Output is correct
16 Correct 3 ms 1408 KB Output is correct
17 Correct 5 ms 2176 KB Output is correct
18 Correct 5 ms 3584 KB Output is correct
19 Correct 5 ms 3840 KB Output is correct
20 Correct 6 ms 3840 KB Output is correct
21 Correct 3 ms 1536 KB Output is correct
22 Correct 5 ms 3456 KB Output is correct
23 Correct 5 ms 3200 KB Output is correct
24 Correct 6 ms 3712 KB Output is correct
25 Correct 6 ms 3840 KB Output is correct
26 Correct 6 ms 3840 KB Output is correct
27 Correct 6 ms 3840 KB Output is correct
28 Correct 5 ms 3840 KB Output is correct
29 Correct 9 ms 3840 KB Output is correct
30 Correct 6 ms 3840 KB Output is correct
31 Correct 7 ms 3840 KB Output is correct
32 Correct 6 ms 3840 KB Output is correct
33 Correct 14 ms 3840 KB Output is correct
34 Correct 14 ms 3840 KB Output is correct
35 Correct 29 ms 3584 KB Output is correct
36 Correct 5 ms 2560 KB Output is correct
37 Correct 24 ms 4736 KB Output is correct
38 Correct 24 ms 4736 KB Output is correct
39 Correct 27 ms 4712 KB Output is correct
40 Correct 25 ms 4736 KB Output is correct
41 Correct 24 ms 4864 KB Output is correct
42 Correct 11 ms 4600 KB Output is correct
43 Correct 11 ms 4600 KB Output is correct
44 Correct 11 ms 4600 KB Output is correct
45 Correct 49 ms 6144 KB Output is correct
46 Correct 48 ms 6272 KB Output is correct
47 Correct 113 ms 22392 KB Output is correct
48 Correct 35 ms 34040 KB Output is correct
49 Correct 35 ms 36856 KB Output is correct
50 Correct 40 ms 40056 KB Output is correct
51 Correct 77 ms 44508 KB Output is correct
52 Correct 82 ms 44408 KB Output is correct
53 Correct 41 ms 42488 KB Output is correct
54 Correct 32 ms 41848 KB Output is correct
55 Correct 32 ms 41848 KB Output is correct
56 Correct 44 ms 43128 KB Output is correct
57 Correct 107 ms 41848 KB Output is correct
58 Correct 40 ms 42732 KB Output is correct
59 Correct 43 ms 42864 KB Output is correct
60 Correct 54 ms 43164 KB Output is correct
61 Correct 46 ms 42968 KB Output is correct
62 Correct 153 ms 44664 KB Output is correct
63 Correct 110 ms 65908 KB Output is correct
64 Correct 127 ms 74664 KB Output is correct
65 Correct 247 ms 72948 KB Output is correct
66 Correct 643 ms 67764 KB Output is correct
67 Correct 639 ms 67184 KB Output is correct