Submission #41506

# Submission time Handle Problem Language Result Execution time Memory
41506 2018-02-17T15:23:48 Z fest Jakarta Skyscrapers (APIO15_skyscraper) C++14
22 / 100
30 ms 30188 KB
// fest
#include <bits/stdc++.h>	

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define FILENAME ""
#define __ fflush(stdout)

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef COMP
		freopen(".in", "r", stdin);
		freopen("2.out", "w", stdout);
	#else
		freopen(FILENAME".in", "r", stdin);
		freopen(FILENAME".out", "w", stdout);
	#endif
}                           

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 3001, inf = 1e9 * 2, MOD = (int)1e9 + 7;

char CH[N];

const ll INF = 1e18;

const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};

bool was[N][N];

int dp[N][N];

vector<int> have[N];

int main() {
  
	int n, m;
	scanf("%d %d", &n, &m);
	int start = 0, finish = 0;
	for (int i = 0; i < m; i++) {
		int b, p;
		scanf("%d %d", &b, &p);
		have[b].pb(p);
		if (i == 0) start = b;
		if (i == 1) finish = b;
	}
	for (int i = 0; i < n; i++) for (int j = 0; j < N; j++) dp[i][j] = inf;
	vector<pair<int, int> > vers;
	for (auto i : have[start]) dp[start][i] = 0, was[start][i] = 1, vers.pb({start, i});
	int l = 0;
	while (l < SZ(vers)) {
		int v = vers[l].F;
		int p = vers[l].S;
		l++;
		if (v + p < n) {
			if (!was[v + p][p]) {
				was[v + p][p] = 1;
				dp[v + p][p] = dp[v][p] + 1;
				vers.pb({v + p, p});
				if (!have[v + p].empty()) {
					if (!was[v + p][have[v + p][0]]) {
						for (auto i : have[v + p]) {
					  	was[v + p][i] = 1;
					  	dp[v + p][i] = dp[v][p] + 1;
					  	vers.pb({v + p, i});
						}
					}
				}
			}	
		}
		if (v - p >= 0) {
			if (!was[v - p][p]) {
				was[v - p][p] = 1;
				dp[v - p][p] = dp[v][p] + 1;
				vers.pb({v - p, p});
				if (!have[v - p].empty()) {
					if (!was[v - p][have[v - p][0]]) {
						for (auto i : have[v - p]) {
					  	was[v - p][i] = 1;
					  	dp[v - p][i] = dp[v][p] + 1;
					  	vers.pb({v - p, i});
						}
					}
				}
			}	
		}
	}
	int out = inf;
	for (int i = 0; i < N; i++) out = min(out, dp[finish][i]);
	if (out == inf) out = -1;
	cout << out;
	return 0;	
}

Compilation message

skyscraper.cpp: In function 'void FREOPEN()':
skyscraper.cpp:25:37: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(FILENAME".in", "r", stdin);
                                     ^
skyscraper.cpp:26:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(FILENAME".out", "w", stdout);
                                       ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50: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:54:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &b, &p);
                         ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 552 KB Output is correct
4 Correct 2 ms 752 KB Output is correct
5 Correct 2 ms 780 KB Output is correct
6 Correct 2 ms 780 KB Output is correct
7 Correct 2 ms 784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 784 KB Output is correct
2 Correct 2 ms 784 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 2 ms 860 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 2 ms 1172 KB Output is correct
9 Correct 2 ms 1536 KB Output is correct
10 Correct 3 ms 2156 KB Output is correct
11 Correct 4 ms 2156 KB Output is correct
12 Correct 3 ms 2160 KB Output is correct
13 Correct 3 ms 2160 KB Output is correct
14 Correct 3 ms 2160 KB Output is correct
15 Correct 3 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 2284 KB Output is correct
3 Correct 2 ms 2284 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 2 ms 2284 KB Output is correct
6 Correct 2 ms 2284 KB Output is correct
7 Correct 2 ms 2284 KB Output is correct
8 Correct 2 ms 2284 KB Output is correct
9 Correct 2 ms 2284 KB Output is correct
10 Correct 3 ms 2284 KB Output is correct
11 Correct 4 ms 2284 KB Output is correct
12 Correct 3 ms 2284 KB Output is correct
13 Correct 3 ms 2284 KB Output is correct
14 Correct 4 ms 2284 KB Output is correct
15 Correct 3 ms 2284 KB Output is correct
16 Correct 3 ms 3056 KB Output is correct
17 Correct 12 ms 11756 KB Output is correct
18 Correct 18 ms 21228 KB Output is correct
19 Correct 20 ms 24172 KB Output is correct
20 Correct 27 ms 30060 KB Output is correct
21 Correct 5 ms 30060 KB Output is correct
22 Correct 17 ms 30060 KB Output is correct
23 Correct 23 ms 30060 KB Output is correct
24 Correct 26 ms 30060 KB Output is correct
25 Correct 26 ms 30188 KB Output is correct
26 Incorrect 24 ms 30188 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 30188 KB Output is correct
2 Correct 2 ms 30188 KB Output is correct
3 Correct 2 ms 30188 KB Output is correct
4 Correct 1 ms 30188 KB Output is correct
5 Correct 2 ms 30188 KB Output is correct
6 Correct 2 ms 30188 KB Output is correct
7 Correct 2 ms 30188 KB Output is correct
8 Correct 2 ms 30188 KB Output is correct
9 Correct 2 ms 30188 KB Output is correct
10 Correct 4 ms 30188 KB Output is correct
11 Correct 3 ms 30188 KB Output is correct
12 Correct 3 ms 30188 KB Output is correct
13 Correct 3 ms 30188 KB Output is correct
14 Correct 3 ms 30188 KB Output is correct
15 Correct 3 ms 30188 KB Output is correct
16 Correct 4 ms 30188 KB Output is correct
17 Correct 12 ms 30188 KB Output is correct
18 Correct 18 ms 30188 KB Output is correct
19 Correct 20 ms 30188 KB Output is correct
20 Correct 25 ms 30188 KB Output is correct
21 Correct 7 ms 30188 KB Output is correct
22 Correct 17 ms 30188 KB Output is correct
23 Correct 21 ms 30188 KB Output is correct
24 Correct 25 ms 30188 KB Output is correct
25 Correct 26 ms 30188 KB Output is correct
26 Incorrect 24 ms 30188 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 30188 KB Output is correct
2 Correct 2 ms 30188 KB Output is correct
3 Correct 1 ms 30188 KB Output is correct
4 Correct 1 ms 30188 KB Output is correct
5 Correct 1 ms 30188 KB Output is correct
6 Correct 2 ms 30188 KB Output is correct
7 Correct 1 ms 30188 KB Output is correct
8 Correct 2 ms 30188 KB Output is correct
9 Correct 2 ms 30188 KB Output is correct
10 Correct 3 ms 30188 KB Output is correct
11 Correct 3 ms 30188 KB Output is correct
12 Correct 3 ms 30188 KB Output is correct
13 Correct 4 ms 30188 KB Output is correct
14 Correct 3 ms 30188 KB Output is correct
15 Correct 3 ms 30188 KB Output is correct
16 Correct 3 ms 30188 KB Output is correct
17 Correct 15 ms 30188 KB Output is correct
18 Correct 17 ms 30188 KB Output is correct
19 Correct 18 ms 30188 KB Output is correct
20 Correct 25 ms 30188 KB Output is correct
21 Correct 6 ms 30188 KB Output is correct
22 Correct 17 ms 30188 KB Output is correct
23 Correct 22 ms 30188 KB Output is correct
24 Correct 29 ms 30188 KB Output is correct
25 Correct 26 ms 30188 KB Output is correct
26 Incorrect 30 ms 30188 KB Output isn't correct
27 Halted 0 ms 0 KB -