Submission #25388

# Submission time Handle Problem Language Result Execution time Memory
25388 2017-06-21T20:31:19 Z gabrielsimoes Jakarta Skyscrapers (APIO15_skyscraper) C++14
22 / 100
0 ms 2984 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
const int MAXN = 3e4;
const ll INF = 4e18+10;

int N, M, X;
vector<int> v[MAXN];
bool ok[MAXN];
ll dp[MAXN];
// int d[MAXN];

ll f(int cur) {
	if (dp[cur] != -1) return dp[cur];

	dp[cur] = INF;
	for (int dx : v[cur]) {
		int i = cur - dx, cnt = 1;
		while (i > 0)
			dp[cur] = min(dp[cur], f(i) + cnt),
			i -= dx, cnt++;
			
		i = cur + dx, cnt = 1;
		while (i < N)
			dp[cur] = min(dp[cur], f(i) + cnt),
			i += dx, cnt++;
	}

	return dp[cur];
}

// int dijkstra() {
// 	for (int i = 0; i < N; i++) d[i] = INF;
// 	d[0] = 0;

// 	int cur = 0;
// 	while (true) {
// 		ok[cur] = true;

// 		for (int dx : v[cur]) {
// 			printf("%d-%d\n",cur,dx);
// 			int i = cur - dx, cnt = 1;
// 			while (i > 0)
// 				d[i] = min(d[i], d[cur] + (cur - i)/dx),
// 				i -= dx, cnt++;

// 			i = cur + dx, cnt = 1;
// 			while (i < N)
// 				d[i] = min(d[i], d[cur] + cnt),
// 				i += dx, cnt++;
// 		}

// 		for (int i = 1; i < N; i++)
// 			if (cur == -1 || d[i] < d[cur])
// 				if (!ok[cur])
// 					cur = i;
// 		if (cur == -1) break;
// 	}

// 	return d[1];
// }

int main()
{
	scanf("%d %d", &N, &M);
	int X, Y;
	for (int i = 0,a,b; i < M; i++) {
		scanf("%d %d", &a, &b);

		if (i == 0) X = a;
		else if (i == 1) Y = a;

		if (b != 0)
			v[a].push_back(b);
	}

	memset(dp, -1, sizeof(dp));
	dp[Y] = 0;
	ll ans = f(X);
	printf("%lld\n", ans < INF ? ans : -1);
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:67:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
                        ^
skyscraper.cpp:70:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
                         ^
skyscraper.cpp:80:11: warning: 'Y' may be used uninitialized in this function [-Wmaybe-uninitialized]
  dp[Y] = 0;
           ^
skyscraper.cpp:68:6: warning: 'X' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int X, Y;
      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2984 KB Output is correct
2 Correct 0 ms 2984 KB Output is correct
3 Correct 0 ms 2984 KB Output is correct
4 Correct 0 ms 2984 KB Output is correct
5 Correct 0 ms 2984 KB Output is correct
6 Correct 0 ms 2984 KB Output is correct
7 Correct 0 ms 2984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2984 KB Output is correct
2 Correct 0 ms 2984 KB Output is correct
3 Correct 0 ms 2984 KB Output is correct
4 Correct 0 ms 2984 KB Output is correct
5 Correct 0 ms 2984 KB Output is correct
6 Correct 0 ms 2984 KB Output is correct
7 Correct 0 ms 2984 KB Output is correct
8 Correct 0 ms 2984 KB Output is correct
9 Correct 0 ms 2984 KB Output is correct
10 Correct 0 ms 2984 KB Output is correct
11 Correct 0 ms 2984 KB Output is correct
12 Correct 0 ms 2984 KB Output is correct
13 Correct 0 ms 2984 KB Output is correct
14 Correct 0 ms 2984 KB Output is correct
15 Correct 0 ms 2984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2984 KB Output is correct
2 Correct 0 ms 2984 KB Output is correct
3 Correct 0 ms 2984 KB Output is correct
4 Correct 0 ms 2984 KB Output is correct
5 Correct 0 ms 2984 KB Output is correct
6 Correct 0 ms 2984 KB Output is correct
7 Correct 0 ms 2984 KB Output is correct
8 Correct 0 ms 2984 KB Output is correct
9 Correct 0 ms 2984 KB Output is correct
10 Correct 0 ms 2984 KB Output is correct
11 Correct 0 ms 2984 KB Output is correct
12 Correct 0 ms 2984 KB Output is correct
13 Correct 0 ms 2984 KB Output is correct
14 Correct 0 ms 2984 KB Output is correct
15 Correct 0 ms 2984 KB Output is correct
16 Correct 0 ms 2984 KB Output is correct
17 Incorrect 0 ms 2984 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2984 KB Output is correct
2 Correct 0 ms 2984 KB Output is correct
3 Correct 0 ms 2984 KB Output is correct
4 Correct 0 ms 2984 KB Output is correct
5 Correct 0 ms 2984 KB Output is correct
6 Correct 0 ms 2984 KB Output is correct
7 Correct 0 ms 2984 KB Output is correct
8 Correct 0 ms 2984 KB Output is correct
9 Correct 0 ms 2984 KB Output is correct
10 Correct 0 ms 2984 KB Output is correct
11 Correct 0 ms 2984 KB Output is correct
12 Correct 0 ms 2984 KB Output is correct
13 Correct 0 ms 2984 KB Output is correct
14 Correct 0 ms 2984 KB Output is correct
15 Correct 0 ms 2984 KB Output is correct
16 Correct 0 ms 2984 KB Output is correct
17 Incorrect 0 ms 2984 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2984 KB Output is correct
2 Correct 0 ms 2984 KB Output is correct
3 Correct 0 ms 2984 KB Output is correct
4 Correct 0 ms 2984 KB Output is correct
5 Correct 0 ms 2984 KB Output is correct
6 Correct 0 ms 2984 KB Output is correct
7 Correct 0 ms 2984 KB Output is correct
8 Correct 0 ms 2984 KB Output is correct
9 Correct 0 ms 2984 KB Output is correct
10 Correct 0 ms 2984 KB Output is correct
11 Correct 0 ms 2984 KB Output is correct
12 Correct 0 ms 2984 KB Output is correct
13 Correct 0 ms 2984 KB Output is correct
14 Correct 0 ms 2984 KB Output is correct
15 Correct 0 ms 2984 KB Output is correct
16 Correct 0 ms 2984 KB Output is correct
17 Incorrect 0 ms 2984 KB Output isn't correct
18 Halted 0 ms 0 KB -