답안 #185666

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
185666 2020-01-12T03:47:45 Z dndhk Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
291 ms 71604 KB
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_N = 30000;
const int INF = 10000000;

int N, M;
vector<pii> gp[MAX_N+1];
int S, E;
vector<pii> vt;
int dist[MAX_N+1];

bool chk[MAX_N+1];

void make_graph(){
	sort(vt.begin(), vt.end());
	vt.erase(unique(vt.begin(), vt.end()), vt.end());
	int s = 0, e = 0, l;
	while(s<vt.size()){
		l = vt[s].first;
		while(e<vt.size()-1 && vt[e+1].first==l){
			e++;
		}
		for(int i=s; i<=e; i++){
			chk[vt[i].second] = true;
		}
		for(int i=s; i<=e; i++){
			int n = vt[i].second, cnt = 0;
			while(1){
				n+=l; cnt++;
				if(n>N)	break;
				//cout<<n<<" "<<vt[i].second<<" "<<cnt<<endl;
				gp[vt[i].second].pb({n, cnt});
				if(chk[n])	break;
			}
			n = vt[i].second; cnt = 0;
			while(1){
				n-=l; cnt++;
				if(n<1)	break;
				//cout<<n<<" "<<vt[i].second<<" "<<cnt<<endl;
				gp[vt[i].second].pb({n, cnt});
				if(chk[n])	break;
			}
		}
		for(int i=s; i<=e; i++){
			chk[vt[i].second] = false;
		}
		s = e+1;
		e = s;
	}
}

priority_queue<pii, vector<pii>, greater<pii> > pq;

void solve(){
	for(int i=1; i<=N; i++)	dist[i] = INF;
	dist[S] = 0;
	pq.push({0, S});
	while(!pq.empty()){
		pii now = pq.top(); pq.pop();
		if(dist[now.second]!=now.first)	continue;
		//cout<<now.second<<" "<<now.first<<endl;
		for(pii i : gp[now.second]){
			if(dist[i.first]>i.second+dist[now.second]){
				//cout<<i.first<<" "<<i.second<<" "<<dist[now.second]<<endl;
				dist[i.first] = i.second+dist[now.second];
				pq.push({dist[i.first], i.first});
			}
		}
	}
}



int main(){
	scanf("%d%d", &N, &M);
	for(int i=0; i<M; i++){
		int a, b; scanf("%d%d", &a, &b);
		a++;
		vt.pb({b, a});
		if(i==0){
			S = a;
		}else if(i==1){
			E = a;
		}
	}
	make_graph();
	solve();	
	if(dist[E]!=INF){
		printf("%d", dist[E]);
	}else{
		printf("-1");
	}
	return 0;
}

Compilation message

skyscraper.cpp: In function 'void make_graph()':
skyscraper.cpp:26:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(s<vt.size()){
        ~^~~~~~~~~~
skyscraper.cpp:28:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(e<vt.size()-1 && vt[e+1].first==l){
         ~^~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:83: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:85:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d%d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 3 ms 1104 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 2 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 4 ms 1144 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 4 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 8 ms 1016 KB Output is correct
6 Correct 0 ms 1016 KB Output is correct
7 Correct 1 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1116 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1144 KB Output is correct
14 Correct 5 ms 1116 KB Output is correct
15 Correct 4 ms 1144 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 4 ms 1272 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 4 ms 1144 KB Output is correct
20 Correct 4 ms 1148 KB Output is correct
21 Correct 3 ms 1016 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 5 ms 1144 KB Output is correct
24 Correct 5 ms 1272 KB Output is correct
25 Correct 5 ms 1144 KB Output is correct
26 Correct 4 ms 1144 KB Output is correct
27 Correct 4 ms 1144 KB Output is correct
28 Correct 5 ms 1272 KB Output is correct
29 Correct 7 ms 1888 KB Output is correct
30 Correct 4 ms 1400 KB Output is correct
31 Correct 5 ms 1528 KB Output is correct
32 Correct 5 ms 1400 KB Output is correct
33 Correct 9 ms 2680 KB Output is correct
34 Correct 9 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1068 KB Output is correct
3 Correct 2 ms 1016 KB Output is correct
4 Correct 1 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1208 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 2 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1148 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 2 ms 1016 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 3 ms 1144 KB Output is correct
16 Correct 3 ms 1016 KB Output is correct
17 Correct 4 ms 1272 KB Output is correct
18 Correct 25 ms 1144 KB Output is correct
19 Correct 3 ms 1148 KB Output is correct
20 Correct 3 ms 1144 KB Output is correct
21 Correct 3 ms 1016 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 4 ms 1272 KB Output is correct
25 Correct 6 ms 1272 KB Output is correct
26 Correct 1 ms 1144 KB Output is correct
27 Correct 3 ms 1148 KB Output is correct
28 Correct 4 ms 1272 KB Output is correct
29 Correct 6 ms 1912 KB Output is correct
30 Correct 4 ms 1400 KB Output is correct
31 Correct 5 ms 1528 KB Output is correct
32 Correct 5 ms 1400 KB Output is correct
33 Correct 9 ms 2568 KB Output is correct
34 Correct 10 ms 2808 KB Output is correct
35 Correct 15 ms 2548 KB Output is correct
36 Correct 5 ms 1332 KB Output is correct
37 Correct 16 ms 3444 KB Output is correct
38 Correct 19 ms 3316 KB Output is correct
39 Correct 23 ms 3316 KB Output is correct
40 Correct 19 ms 3316 KB Output is correct
41 Correct 17 ms 3316 KB Output is correct
42 Correct 8 ms 1656 KB Output is correct
43 Correct 9 ms 1656 KB Output is correct
44 Correct 8 ms 1656 KB Output is correct
45 Correct 29 ms 6132 KB Output is correct
46 Correct 29 ms 6260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 3 ms 1020 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1020 KB Output is correct
10 Correct 2 ms 888 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 4 ms 1144 KB Output is correct
14 Correct 3 ms 1144 KB Output is correct
15 Correct 4 ms 1148 KB Output is correct
16 Correct 3 ms 1144 KB Output is correct
17 Correct 4 ms 1272 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 3 ms 1144 KB Output is correct
21 Correct 8 ms 1020 KB Output is correct
22 Correct 0 ms 1144 KB Output is correct
23 Correct 3 ms 1144 KB Output is correct
24 Correct 4 ms 1272 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 3 ms 1144 KB Output is correct
27 Correct 4 ms 1144 KB Output is correct
28 Correct 4 ms 1276 KB Output is correct
29 Correct 6 ms 1912 KB Output is correct
30 Correct 4 ms 1400 KB Output is correct
31 Correct 5 ms 1528 KB Output is correct
32 Correct 4 ms 1400 KB Output is correct
33 Correct 9 ms 2572 KB Output is correct
34 Correct 16 ms 2680 KB Output is correct
35 Correct 15 ms 2604 KB Output is correct
36 Correct 6 ms 1272 KB Output is correct
37 Correct 18 ms 3572 KB Output is correct
38 Correct 20 ms 3356 KB Output is correct
39 Correct 19 ms 3316 KB Output is correct
40 Correct 21 ms 3316 KB Output is correct
41 Correct 21 ms 3316 KB Output is correct
42 Correct 10 ms 1656 KB Output is correct
43 Correct 10 ms 1656 KB Output is correct
44 Correct 10 ms 1656 KB Output is correct
45 Correct 42 ms 6260 KB Output is correct
46 Correct 28 ms 6260 KB Output is correct
47 Correct 52 ms 10948 KB Output is correct
48 Correct 21 ms 3952 KB Output is correct
49 Correct 18 ms 3060 KB Output is correct
50 Correct 14 ms 2936 KB Output is correct
51 Correct 54 ms 5848 KB Output is correct
52 Correct 46 ms 6256 KB Output is correct
53 Correct 25 ms 3196 KB Output is correct
54 Correct 6 ms 1656 KB Output is correct
55 Correct 7 ms 2040 KB Output is correct
56 Correct 19 ms 2688 KB Output is correct
57 Correct 49 ms 10100 KB Output is correct
58 Correct 9 ms 2520 KB Output is correct
59 Correct 17 ms 2928 KB Output is correct
60 Correct 16 ms 3572 KB Output is correct
61 Correct 30 ms 2932 KB Output is correct
62 Correct 30 ms 6772 KB Output is correct
63 Correct 99 ms 25252 KB Output is correct
64 Correct 121 ms 33564 KB Output is correct
65 Correct 155 ms 43372 KB Output is correct
66 Correct 291 ms 71604 KB Output is correct
67 Correct 270 ms 71488 KB Output is correct