Submission #43577

# Submission time Handle Problem Language Result Execution time Memory
43577 2018-03-17T23:24:45 Z RezwanArefin01 Jakarta Skyscrapers (APIO15_skyscraper) C++14
22 / 100
24 ms 25948 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii; 

const int maxn = 2010;
vector<int> jump[maxn];
int n, m, b[maxn], p[maxn], dp[2010][2010], vis[2010][2010];
vector<ii> adj[maxn]; 

int f(int u, int len) {
	if(u == b[1]) return 0;
	if(vis[u][len] == 1) return 1e9;

	int &ret = dp[u][len]; 
	if(vis[u][len] == 2) return ret; 

	vis[u][len] = 1;
	ret = 1e9;
	if(u + len < n) ret = 1 + f(u + len, len);
	if(u - len >= 0) ret = min(ret, 1 + f(u - len, len));

	for(ii v : adj[u]) ret = min(ret, 1 + f(v.first, v.second)); 

	vis[u][len] = 2; 
	return ret ;
}
int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
	freopen("in", "r", stdin);
#endif
	scanf("%d %d", &n, &m);
	
	for(int i = 0; i < m; i++) {
		scanf("%d %d", &b[i], &p[i]); 
		jump[b[i]].push_back(p[i]); 
	}	
	for(int i = 0; i < n; i++) {
		sort(jump[i].begin(), jump[i].end()); 
		jump[i].erase(unique(jump[i].begin(), jump[i].end()), jump[i].end()); 

		for(int p : jump[i]) {
			if(i + p < n) adj[i].emplace_back(i + p, p);
			if(i - p >= 0) adj[i].emplace_back(i - p, p);  

		} 
	}

	memset(dp, -1, sizeof dp);
	int ret = f(b[0], p[0]); 
	if(ret >= 1e8) cout << "-1" << endl;
	else cout << ret << endl;

}

Compilation message

skyscraper.cpp: In function 'int main(int, const char**)':
skyscraper.cpp:33: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:36:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &b[i], &p[i]); 
                               ^
# Verdict Execution time Memory Grader output
1 Correct 13 ms 16248 KB Output is correct
2 Correct 13 ms 16252 KB Output is correct
3 Correct 13 ms 16468 KB Output is correct
4 Correct 14 ms 16528 KB Output is correct
5 Correct 13 ms 16572 KB Output is correct
6 Correct 13 ms 16572 KB Output is correct
7 Correct 13 ms 16572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 16572 KB Output is correct
2 Correct 13 ms 16604 KB Output is correct
3 Correct 13 ms 16624 KB Output is correct
4 Correct 13 ms 16624 KB Output is correct
5 Correct 13 ms 16624 KB Output is correct
6 Correct 13 ms 16624 KB Output is correct
7 Correct 14 ms 16624 KB Output is correct
8 Correct 13 ms 16804 KB Output is correct
9 Correct 13 ms 16804 KB Output is correct
10 Correct 14 ms 17020 KB Output is correct
11 Correct 15 ms 17280 KB Output is correct
12 Correct 13 ms 17280 KB Output is correct
13 Correct 15 ms 17280 KB Output is correct
14 Correct 15 ms 17280 KB Output is correct
15 Correct 15 ms 17280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 17280 KB Output is correct
2 Correct 13 ms 17280 KB Output is correct
3 Correct 13 ms 17280 KB Output is correct
4 Correct 13 ms 17280 KB Output is correct
5 Correct 16 ms 17280 KB Output is correct
6 Correct 13 ms 17280 KB Output is correct
7 Correct 13 ms 17280 KB Output is correct
8 Correct 13 ms 17280 KB Output is correct
9 Correct 18 ms 17280 KB Output is correct
10 Correct 13 ms 17280 KB Output is correct
11 Correct 15 ms 17296 KB Output is correct
12 Correct 14 ms 17296 KB Output is correct
13 Correct 17 ms 17296 KB Output is correct
14 Correct 17 ms 17332 KB Output is correct
15 Correct 15 ms 17344 KB Output is correct
16 Correct 13 ms 17344 KB Output is correct
17 Correct 19 ms 21220 KB Output is correct
18 Correct 14 ms 21220 KB Output is correct
19 Correct 14 ms 21220 KB Output is correct
20 Correct 22 ms 25096 KB Output is correct
21 Correct 13 ms 25096 KB Output is correct
22 Correct 13 ms 25096 KB Output is correct
23 Incorrect 22 ms 25580 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25580 KB Output is correct
2 Correct 13 ms 25580 KB Output is correct
3 Correct 13 ms 25580 KB Output is correct
4 Correct 13 ms 25580 KB Output is correct
5 Correct 13 ms 25580 KB Output is correct
6 Correct 14 ms 25580 KB Output is correct
7 Correct 13 ms 25580 KB Output is correct
8 Correct 15 ms 25580 KB Output is correct
9 Correct 13 ms 25580 KB Output is correct
10 Correct 13 ms 25580 KB Output is correct
11 Correct 14 ms 25580 KB Output is correct
12 Correct 14 ms 25580 KB Output is correct
13 Correct 17 ms 25580 KB Output is correct
14 Correct 24 ms 25580 KB Output is correct
15 Correct 15 ms 25580 KB Output is correct
16 Correct 14 ms 25580 KB Output is correct
17 Correct 20 ms 25580 KB Output is correct
18 Correct 14 ms 25580 KB Output is correct
19 Correct 13 ms 25580 KB Output is correct
20 Correct 22 ms 25580 KB Output is correct
21 Correct 14 ms 25580 KB Output is correct
22 Correct 13 ms 25580 KB Output is correct
23 Incorrect 22 ms 25832 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25832 KB Output is correct
2 Correct 13 ms 25832 KB Output is correct
3 Correct 13 ms 25832 KB Output is correct
4 Correct 13 ms 25832 KB Output is correct
5 Correct 13 ms 25832 KB Output is correct
6 Correct 13 ms 25832 KB Output is correct
7 Correct 13 ms 25832 KB Output is correct
8 Correct 13 ms 25832 KB Output is correct
9 Correct 13 ms 25832 KB Output is correct
10 Correct 13 ms 25832 KB Output is correct
11 Correct 14 ms 25832 KB Output is correct
12 Correct 13 ms 25832 KB Output is correct
13 Correct 14 ms 25832 KB Output is correct
14 Correct 14 ms 25832 KB Output is correct
15 Correct 15 ms 25832 KB Output is correct
16 Correct 13 ms 25832 KB Output is correct
17 Correct 19 ms 25832 KB Output is correct
18 Correct 13 ms 25832 KB Output is correct
19 Correct 13 ms 25832 KB Output is correct
20 Correct 21 ms 25832 KB Output is correct
21 Correct 14 ms 25832 KB Output is correct
22 Correct 14 ms 25832 KB Output is correct
23 Incorrect 23 ms 25948 KB Output isn't correct
24 Halted 0 ms 0 KB -