답안 #32897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
32897 2017-10-17T00:33:07 Z minimario Jakarta Skyscrapers (APIO15_skyscraper) C++14
22 / 100
63 ms 80748 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> pii;
typedef long long ll;
 
#define f first
#define s second
 
const int MAX = 30005;
const int SQRT = 85;
const int INF = 1000000000;
int p[MAX], len[MAX]; // position, length
 
vector<pair<int, int> > g[MAX*SQRT+SQRT];
vector<int> powers[MAX]; // powers of doges at a given position
 
int dist[MAX*SQRT+SQRT];
 
priority_queue<pair<int, int> > pq;
int xd = 0;
void dijk(int i) {
	dist[i] = 0;
	//cout << i << " " << j << " " << 0 << endl;
	pq.push({0, i});
	while (!pq.empty()) {
		xd += 1;
		auto top = pq.top(); pq.pop();
		int d = -top.f;
		int loc = top.s;
		if (d > dist[loc]) {
			continue; 
		}
		//cout << loc.f << " " << loc.s << endl;
		for (auto i : g[loc]) {
			//cout << i.f.f << " " << i.f.s << endl;
			int d_new = (d + i.s);
			if (d_new < dist[i.f]) {
				dist[i.f] = d_new;
				//cout << "came from: " << loc.f << " " << loc.s << endl;
				//cout << i.f.f << " " << i.f.s << " " << d_new << endl;
				pq.push({-d_new, i.f});
 
			}
		}
 
	}
}
int main() {
	//freopen("a.in", "r", stdin);
	//freopen("a.out", "w", stdout);
	for (int i=0; i<MAX; i++) {
		for (int j=0; j<SQRT; j++) {
			dist[i*SQRT+j] = INF; 
		}
	}
 
	int n, m; scanf("%d %d", &n, &m);
	for (int i=0; i<m; i++) {
		scanf("%d %d", &p[i], &len[i]);
		powers[p[i]].push_back(len[i]);
	}
	
	for (int i=0; i<n; i++) {
		for (int j=1; j<SQRT; j++) {
			g[i*SQRT+j].push_back({i*SQRT, 0});
		}
		for (int j : powers[i]) {
			if (j < SQRT) {
				g[i*SQRT].push_back({i*SQRT+j, 0});
			}
		}
	}
	
	for (int i=0; i<m; i++) {
		if (len[i] > SQRT) {
			for (int j=p[i]+len[i]; j<n; j+=len[i]) {
				g[p[i]*SQRT].push_back({j*SQRT, (j-p[i])/len[i]});
			}
			for (int j=p[i]-len[i]; j>=0; j-=len[i]) {
				g[p[i]*SQRT].push_back({j*SQRT, (p[i]-j)/len[i]});
			}
		}
	}
 
	for (int i=0; i<n; i++) {
		for (int j=1; j<SQRT; j++) {
			if (i-j >= 0) { g[i*SQRT+j].push_back({(i-j)*SQRT+j, 1}); }
			if (i+j < n) { g[i*SQRT+j].push_back({(i+j)*SQRT+j, 1}); }
		}
	}
	
	/*
	int ct = 0;
	for (int i=0; i<MAX; i++) {
		for (int j=0; j<SQRT; j++) {
			ct += g[i][j].size();
		}
	}
	cout << ct << endl;
	*/
	dijk(p[0]*SQRT);
	if (dist[p[1]*SQRT] == INF) { printf("%d\n", -1); }
	else { printf("%d\n", dist[p[1]*SQRT]); }
	//cout << xd << endl;
}	

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:58:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n, m; scanf("%d %d", &n, &m);
                                  ^
skyscraper.cpp:60:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &p[i], &len[i]);
                                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 72696 KB Output is correct
2 Correct 26 ms 72696 KB Output is correct
3 Correct 13 ms 72696 KB Output is correct
4 Correct 26 ms 72696 KB Output is correct
5 Correct 36 ms 72696 KB Output is correct
6 Correct 29 ms 72696 KB Output is correct
7 Correct 13 ms 72696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 72696 KB Output is correct
2 Correct 26 ms 72696 KB Output is correct
3 Correct 26 ms 72696 KB Output is correct
4 Correct 19 ms 72696 KB Output is correct
5 Correct 23 ms 72696 KB Output is correct
6 Correct 26 ms 72696 KB Output is correct
7 Correct 13 ms 72696 KB Output is correct
8 Correct 23 ms 72828 KB Output is correct
9 Correct 16 ms 72964 KB Output is correct
10 Correct 26 ms 73092 KB Output is correct
11 Correct 23 ms 73092 KB Output is correct
12 Correct 9 ms 73092 KB Output is correct
13 Correct 19 ms 73092 KB Output is correct
14 Correct 19 ms 73092 KB Output is correct
15 Correct 16 ms 73092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 72696 KB Output is correct
2 Correct 16 ms 72696 KB Output is correct
3 Correct 26 ms 72696 KB Output is correct
4 Correct 19 ms 72696 KB Output is correct
5 Correct 19 ms 72696 KB Output is correct
6 Correct 9 ms 72696 KB Output is correct
7 Correct 9 ms 72696 KB Output is correct
8 Correct 16 ms 72828 KB Output is correct
9 Correct 16 ms 72964 KB Output is correct
10 Correct 9 ms 73092 KB Output is correct
11 Correct 26 ms 73092 KB Output is correct
12 Correct 23 ms 73092 KB Output is correct
13 Correct 19 ms 73092 KB Output is correct
14 Correct 19 ms 73092 KB Output is correct
15 Correct 23 ms 73092 KB Output is correct
16 Correct 23 ms 73488 KB Output is correct
17 Correct 39 ms 75740 KB Output is correct
18 Correct 39 ms 79560 KB Output is correct
19 Correct 49 ms 80616 KB Output is correct
20 Correct 56 ms 80748 KB Output is correct
21 Correct 23 ms 74284 KB Output is correct
22 Correct 39 ms 79692 KB Output is correct
23 Correct 46 ms 79032 KB Output is correct
24 Correct 46 ms 80220 KB Output is correct
25 Correct 56 ms 80616 KB Output is correct
26 Correct 53 ms 80616 KB Output is correct
27 Correct 53 ms 80620 KB Output is correct
28 Incorrect 39 ms 80616 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 72696 KB Output is correct
2 Correct 23 ms 72696 KB Output is correct
3 Correct 13 ms 72696 KB Output is correct
4 Correct 16 ms 72696 KB Output is correct
5 Correct 13 ms 72696 KB Output is correct
6 Correct 13 ms 72696 KB Output is correct
7 Correct 23 ms 72696 KB Output is correct
8 Correct 23 ms 72828 KB Output is correct
9 Correct 19 ms 72964 KB Output is correct
10 Correct 16 ms 73092 KB Output is correct
11 Correct 19 ms 73092 KB Output is correct
12 Correct 19 ms 73092 KB Output is correct
13 Correct 19 ms 73092 KB Output is correct
14 Correct 23 ms 73092 KB Output is correct
15 Correct 19 ms 73092 KB Output is correct
16 Correct 19 ms 73488 KB Output is correct
17 Correct 33 ms 75740 KB Output is correct
18 Correct 46 ms 79560 KB Output is correct
19 Correct 49 ms 80616 KB Output is correct
20 Correct 63 ms 80748 KB Output is correct
21 Correct 43 ms 74284 KB Output is correct
22 Correct 36 ms 79692 KB Output is correct
23 Correct 49 ms 79032 KB Output is correct
24 Correct 63 ms 80220 KB Output is correct
25 Correct 53 ms 80616 KB Output is correct
26 Correct 53 ms 80616 KB Output is correct
27 Correct 43 ms 80620 KB Output is correct
28 Incorrect 49 ms 80616 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 72696 KB Output is correct
2 Correct 26 ms 72696 KB Output is correct
3 Correct 19 ms 72696 KB Output is correct
4 Correct 23 ms 72696 KB Output is correct
5 Correct 19 ms 72696 KB Output is correct
6 Correct 19 ms 72696 KB Output is correct
7 Correct 23 ms 72696 KB Output is correct
8 Correct 29 ms 72828 KB Output is correct
9 Correct 23 ms 72964 KB Output is correct
10 Correct 23 ms 73092 KB Output is correct
11 Correct 23 ms 73092 KB Output is correct
12 Correct 19 ms 73092 KB Output is correct
13 Correct 26 ms 73092 KB Output is correct
14 Correct 23 ms 73092 KB Output is correct
15 Correct 36 ms 73092 KB Output is correct
16 Correct 29 ms 73488 KB Output is correct
17 Correct 23 ms 75740 KB Output is correct
18 Correct 46 ms 79560 KB Output is correct
19 Correct 53 ms 80616 KB Output is correct
20 Correct 39 ms 80748 KB Output is correct
21 Correct 19 ms 74284 KB Output is correct
22 Correct 53 ms 79692 KB Output is correct
23 Correct 49 ms 79032 KB Output is correct
24 Correct 53 ms 80220 KB Output is correct
25 Correct 49 ms 80616 KB Output is correct
26 Correct 43 ms 80616 KB Output is correct
27 Correct 39 ms 80620 KB Output is correct
28 Incorrect 36 ms 80616 KB Output isn't correct
29 Halted 0 ms 0 KB -