답안 #531128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531128 2022-02-27T19:41:14 Z Hanksburger Jakarta Skyscrapers (APIO15_skyscraper) C++17
36 / 100
146 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[10500005];
int dist[10500005], a[30005][175];
deque<int> deq;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m, s, t, sz;
	cin >> n >> m;
	sz=n;
	for (int i=0; i<m; i++)
	{
		int b, p;
		cin >> b >> p;
		if (i==0)
			s=b;
		else if (i==1)
			t=b;
		if (p*p<=m)
		{
			if (!a[b][p])
			{
				a[b%p][p]=sz;
				sz++;
				adj[a[b%p][p]].push_back({b%p, 0});
				for (int j=b%p+p; j<n; j+=p)
				{
					a[j][p]=sz;
					sz++;
					adj[a[j][p]].push_back({j, 0});
					adj[a[j][p]].push_back({a[j-p][p], 1});
					adj[a[j-p][p]].push_back({a[j][p], 1});
				}
			}
			adj[b].push_back({a[b][p], 0});
		}
		else
		{
			int prev=b;
			for (int j=b-p; j>=0; j-=p)
			{
				adj[prev].push_back({sz, 1});
				adj[sz].push_back({j, 0});
				prev=sz;
				sz++;
			}
			prev=b;
			for (int j=b+p; j<n; j+=p)
			{
				adj[prev].push_back({sz, 1});
				adj[sz].push_back({j, 0});
				prev=sz;
				sz++;
			}
		}
	}
	for (int i=0; i<sz; i++)
		dist[i]=1e9;
	dist[s]=0;
	deq.push_back(s);
	while (!deq.empty())
	{
		int u=deq.front();
		deq.pop_front();
		for (int i=0; i<adj[u].size(); i++)
		{
			int v=adj[u][i].first, w=adj[u][i].second;
			if (dist[v]==1e9)
			{
				dist[v]=dist[u]+w;
				if (w)
					deq.push_back(v);
				else
					deq.push_front(v);
			}
		}
	}
	if (dist[t]==1e9)
		cout << -1;
	else
		cout << dist[t];
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for (int i=0; i<adj[u].size(); i++)
      |                 ~^~~~~~~~~~~~~~
skyscraper.cpp:81:12: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   81 |  if (dist[t]==1e9)
      |      ~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 246852 KB Output is correct
2 Correct 118 ms 247036 KB Output is correct
3 Correct 128 ms 246872 KB Output is correct
4 Correct 131 ms 246876 KB Output is correct
5 Correct 114 ms 246832 KB Output is correct
6 Correct 129 ms 246876 KB Output is correct
7 Correct 125 ms 246840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 246864 KB Output is correct
2 Correct 115 ms 246840 KB Output is correct
3 Correct 135 ms 246852 KB Output is correct
4 Correct 121 ms 246940 KB Output is correct
5 Correct 114 ms 246808 KB Output is correct
6 Correct 117 ms 246868 KB Output is correct
7 Correct 115 ms 246788 KB Output is correct
8 Correct 114 ms 246852 KB Output is correct
9 Correct 121 ms 246852 KB Output is correct
10 Correct 116 ms 247012 KB Output is correct
11 Correct 116 ms 247036 KB Output is correct
12 Correct 122 ms 246980 KB Output is correct
13 Correct 120 ms 247004 KB Output is correct
14 Correct 116 ms 247172 KB Output is correct
15 Correct 114 ms 247136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 246876 KB Output is correct
2 Correct 115 ms 246856 KB Output is correct
3 Correct 117 ms 246788 KB Output is correct
4 Correct 117 ms 246800 KB Output is correct
5 Correct 115 ms 246888 KB Output is correct
6 Correct 115 ms 246852 KB Output is correct
7 Correct 121 ms 246768 KB Output is correct
8 Correct 131 ms 246916 KB Output is correct
9 Correct 121 ms 246908 KB Output is correct
10 Correct 118 ms 246964 KB Output is correct
11 Correct 115 ms 247036 KB Output is correct
12 Correct 116 ms 247004 KB Output is correct
13 Correct 118 ms 246964 KB Output is correct
14 Correct 141 ms 247124 KB Output is correct
15 Correct 117 ms 247184 KB Output is correct
16 Correct 121 ms 247212 KB Output is correct
17 Correct 119 ms 247972 KB Output is correct
18 Correct 119 ms 248260 KB Output is correct
19 Correct 117 ms 248420 KB Output is correct
20 Correct 118 ms 248388 KB Output is correct
21 Correct 119 ms 247156 KB Output is correct
22 Correct 118 ms 248288 KB Output is correct
23 Correct 117 ms 248236 KB Output is correct
24 Correct 120 ms 248656 KB Output is correct
25 Correct 122 ms 248492 KB Output is correct
26 Correct 125 ms 248720 KB Output is correct
27 Correct 128 ms 248612 KB Output is correct
28 Correct 121 ms 249140 KB Output is correct
29 Correct 123 ms 250976 KB Output is correct
30 Correct 121 ms 249028 KB Output is correct
31 Correct 120 ms 249360 KB Output is correct
32 Correct 126 ms 249008 KB Output is correct
33 Correct 135 ms 253648 KB Output is correct
34 Correct 136 ms 253748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 246820 KB Output is correct
2 Correct 115 ms 246840 KB Output is correct
3 Correct 117 ms 246836 KB Output is correct
4 Correct 116 ms 246836 KB Output is correct
5 Correct 124 ms 246836 KB Output is correct
6 Correct 122 ms 246772 KB Output is correct
7 Correct 121 ms 246836 KB Output is correct
8 Correct 119 ms 246896 KB Output is correct
9 Correct 122 ms 246948 KB Output is correct
10 Correct 117 ms 246976 KB Output is correct
11 Correct 117 ms 247056 KB Output is correct
12 Correct 121 ms 246932 KB Output is correct
13 Correct 117 ms 246968 KB Output is correct
14 Correct 115 ms 247208 KB Output is correct
15 Correct 112 ms 247172 KB Output is correct
16 Correct 110 ms 247132 KB Output is correct
17 Correct 122 ms 247904 KB Output is correct
18 Correct 121 ms 248364 KB Output is correct
19 Correct 112 ms 248356 KB Output is correct
20 Correct 113 ms 248340 KB Output is correct
21 Correct 111 ms 247188 KB Output is correct
22 Correct 112 ms 248420 KB Output is correct
23 Correct 112 ms 248264 KB Output is correct
24 Correct 111 ms 248644 KB Output is correct
25 Correct 115 ms 248508 KB Output is correct
26 Correct 114 ms 248648 KB Output is correct
27 Correct 114 ms 248628 KB Output is correct
28 Correct 113 ms 249156 KB Output is correct
29 Correct 131 ms 250904 KB Output is correct
30 Correct 114 ms 248832 KB Output is correct
31 Correct 116 ms 249620 KB Output is correct
32 Correct 115 ms 249004 KB Output is correct
33 Correct 130 ms 253624 KB Output is correct
34 Correct 127 ms 253704 KB Output is correct
35 Correct 126 ms 251876 KB Output is correct
36 Correct 127 ms 248352 KB Output is correct
37 Correct 143 ms 255832 KB Output is correct
38 Correct 137 ms 254912 KB Output is correct
39 Correct 145 ms 254916 KB Output is correct
40 Correct 145 ms 255100 KB Output is correct
41 Correct 139 ms 254916 KB Output is correct
42 Correct 116 ms 249120 KB Output is correct
43 Correct 115 ms 249156 KB Output is correct
44 Correct 116 ms 248932 KB Output is correct
45 Runtime error 132 ms 262148 KB Execution killed with signal 9
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 246820 KB Output is correct
2 Correct 111 ms 246852 KB Output is correct
3 Correct 110 ms 246848 KB Output is correct
4 Correct 112 ms 246896 KB Output is correct
5 Correct 111 ms 246820 KB Output is correct
6 Correct 111 ms 246876 KB Output is correct
7 Correct 110 ms 246780 KB Output is correct
8 Correct 111 ms 246840 KB Output is correct
9 Correct 118 ms 247028 KB Output is correct
10 Correct 114 ms 246980 KB Output is correct
11 Correct 112 ms 247144 KB Output is correct
12 Correct 112 ms 246952 KB Output is correct
13 Correct 117 ms 246972 KB Output is correct
14 Correct 118 ms 247304 KB Output is correct
15 Correct 113 ms 247184 KB Output is correct
16 Correct 114 ms 247064 KB Output is correct
17 Correct 114 ms 247936 KB Output is correct
18 Correct 116 ms 248316 KB Output is correct
19 Correct 115 ms 248332 KB Output is correct
20 Correct 113 ms 248368 KB Output is correct
21 Correct 112 ms 247200 KB Output is correct
22 Correct 112 ms 248256 KB Output is correct
23 Correct 115 ms 248232 KB Output is correct
24 Correct 114 ms 248684 KB Output is correct
25 Correct 114 ms 248516 KB Output is correct
26 Correct 113 ms 248612 KB Output is correct
27 Correct 113 ms 248516 KB Output is correct
28 Correct 121 ms 249132 KB Output is correct
29 Correct 118 ms 250964 KB Output is correct
30 Correct 112 ms 248772 KB Output is correct
31 Correct 119 ms 249396 KB Output is correct
32 Correct 115 ms 249284 KB Output is correct
33 Correct 127 ms 253732 KB Output is correct
34 Correct 129 ms 253720 KB Output is correct
35 Correct 127 ms 251956 KB Output is correct
36 Correct 123 ms 248244 KB Output is correct
37 Correct 146 ms 255844 KB Output is correct
38 Correct 141 ms 254872 KB Output is correct
39 Correct 143 ms 254916 KB Output is correct
40 Correct 142 ms 254988 KB Output is correct
41 Correct 142 ms 255088 KB Output is correct
42 Correct 123 ms 249216 KB Output is correct
43 Correct 127 ms 249156 KB Output is correct
44 Correct 116 ms 248936 KB Output is correct
45 Runtime error 136 ms 262148 KB Execution killed with signal 9
46 Halted 0 ms 0 KB -