Submission #41421

# Submission time Handle Problem Language Result Execution time Memory
41421 2018-02-17T08:00:17 Z fest Jakarta Skyscrapers (APIO15_skyscraper) C++14
22 / 100
21 ms 20460 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 = 2001, 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 1 ms 380 KB Output is correct
2 Correct 1 ms 480 KB Output is correct
3 Correct 1 ms 480 KB Output is correct
4 Correct 2 ms 568 KB Output is correct
5 Correct 1 ms 624 KB Output is correct
6 Correct 2 ms 660 KB Output is correct
7 Correct 2 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 728 KB Output is correct
2 Correct 1 ms 728 KB Output is correct
3 Correct 1 ms 728 KB Output is correct
4 Correct 1 ms 728 KB Output is correct
5 Correct 2 ms 732 KB Output is correct
6 Correct 2 ms 732 KB Output is correct
7 Correct 2 ms 732 KB Output is correct
8 Correct 2 ms 1088 KB Output is correct
9 Correct 2 ms 1116 KB Output is correct
10 Correct 2 ms 1628 KB Output is correct
11 Correct 3 ms 1644 KB Output is correct
12 Correct 3 ms 1644 KB Output is correct
13 Correct 2 ms 1644 KB Output is correct
14 Correct 3 ms 1772 KB Output is correct
15 Correct 3 ms 1772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1772 KB Output is correct
2 Correct 1 ms 1772 KB Output is correct
3 Correct 1 ms 1772 KB Output is correct
4 Correct 2 ms 1772 KB Output is correct
5 Correct 1 ms 1772 KB Output is correct
6 Correct 2 ms 1772 KB Output is correct
7 Correct 1 ms 1772 KB Output is correct
8 Correct 2 ms 1772 KB Output is correct
9 Correct 2 ms 1772 KB Output is correct
10 Correct 3 ms 1772 KB Output is correct
11 Correct 3 ms 1772 KB Output is correct
12 Correct 3 ms 1772 KB Output is correct
13 Correct 2 ms 1772 KB Output is correct
14 Correct 3 ms 1772 KB Output is correct
15 Correct 3 ms 1772 KB Output is correct
16 Correct 3 ms 2156 KB Output is correct
17 Correct 9 ms 8172 KB Output is correct
18 Correct 13 ms 14316 KB Output is correct
19 Correct 14 ms 16364 KB Output is correct
20 Correct 20 ms 20460 KB Output is correct
21 Correct 4 ms 20460 KB Output is correct
22 Correct 12 ms 20460 KB Output is correct
23 Correct 16 ms 20460 KB Output is correct
24 Correct 19 ms 20460 KB Output is correct
25 Correct 19 ms 20460 KB Output is correct
26 Incorrect 18 ms 20460 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 20460 KB Output is correct
2 Correct 2 ms 20460 KB Output is correct
3 Correct 2 ms 20460 KB Output is correct
4 Correct 2 ms 20460 KB Output is correct
5 Correct 2 ms 20460 KB Output is correct
6 Correct 2 ms 20460 KB Output is correct
7 Correct 2 ms 20460 KB Output is correct
8 Correct 2 ms 20460 KB Output is correct
9 Correct 2 ms 20460 KB Output is correct
10 Correct 2 ms 20460 KB Output is correct
11 Correct 3 ms 20460 KB Output is correct
12 Correct 2 ms 20460 KB Output is correct
13 Correct 2 ms 20460 KB Output is correct
14 Correct 3 ms 20460 KB Output is correct
15 Correct 3 ms 20460 KB Output is correct
16 Correct 3 ms 20460 KB Output is correct
17 Correct 9 ms 20460 KB Output is correct
18 Correct 12 ms 20460 KB Output is correct
19 Correct 13 ms 20460 KB Output is correct
20 Correct 21 ms 20460 KB Output is correct
21 Correct 4 ms 20460 KB Output is correct
22 Correct 12 ms 20460 KB Output is correct
23 Correct 15 ms 20460 KB Output is correct
24 Correct 19 ms 20460 KB Output is correct
25 Correct 18 ms 20460 KB Output is correct
26 Incorrect 18 ms 20460 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 20460 KB Output is correct
2 Correct 2 ms 20460 KB Output is correct
3 Correct 1 ms 20460 KB Output is correct
4 Correct 1 ms 20460 KB Output is correct
5 Correct 2 ms 20460 KB Output is correct
6 Correct 1 ms 20460 KB Output is correct
7 Correct 2 ms 20460 KB Output is correct
8 Correct 2 ms 20460 KB Output is correct
9 Correct 2 ms 20460 KB Output is correct
10 Correct 2 ms 20460 KB Output is correct
11 Correct 3 ms 20460 KB Output is correct
12 Correct 3 ms 20460 KB Output is correct
13 Correct 3 ms 20460 KB Output is correct
14 Correct 3 ms 20460 KB Output is correct
15 Correct 3 ms 20460 KB Output is correct
16 Correct 3 ms 20460 KB Output is correct
17 Correct 9 ms 20460 KB Output is correct
18 Correct 14 ms 20460 KB Output is correct
19 Correct 14 ms 20460 KB Output is correct
20 Correct 19 ms 20460 KB Output is correct
21 Correct 4 ms 20460 KB Output is correct
22 Correct 12 ms 20460 KB Output is correct
23 Correct 17 ms 20460 KB Output is correct
24 Correct 19 ms 20460 KB Output is correct
25 Correct 19 ms 20460 KB Output is correct
26 Incorrect 18 ms 20460 KB Output isn't correct
27 Halted 0 ms 0 KB -