Submission #41508

# Submission time Handle Problem Language Result Execution time Memory
41508 2018-02-17T15:26:30 Z fest Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 7404 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("1.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 = 200500, 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};

int dp[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++) sort(All(have[i]));
	for (int i = 0; i < n; i++) dp[i] = inf;
	dp[start] = 0;
	set<pair<int, int> > s;
	s.insert({0, start});
	while (!s.empty()) {
		int v = s.begin() -> S;
		s.erase(s.begin());
		for (auto p : have[v]) {
			for (int mul = 1; v + mul * p < n; mul++) {
				int u = v + mul * p;
				if (dp[u] > dp[v] + mul) {
					s.erase({dp[u], u});
					dp[u] = dp[v] + mul;
					s.insert({dp[u], u});
				}
				if (binary_search(All(have[u]), p)) break;
			}
			for (int mul = 1; v - mul * p >= 0; mul++) {
				int u = v - mul * p;
				if (dp[u] > dp[v] + mul) {
					s.erase({dp[u], u});
					dp[u] = dp[v] + mul;
					s.insert({dp[u], u});
				}
        if (binary_search(All(have[u]), p)) break;
			} 	
		}
	}
	if (dp[finish] == inf) dp[finish] = -1;
	cout << dp[finish];
	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:48: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:52: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 6 ms 4984 KB Output is correct
2 Correct 5 ms 5088 KB Output is correct
3 Correct 5 ms 5148 KB Output is correct
4 Correct 5 ms 5184 KB Output is correct
5 Correct 5 ms 5224 KB Output is correct
6 Correct 5 ms 5224 KB Output is correct
7 Correct 5 ms 5300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5300 KB Output is correct
2 Correct 5 ms 5300 KB Output is correct
3 Correct 6 ms 5300 KB Output is correct
4 Correct 5 ms 5372 KB Output is correct
5 Correct 5 ms 5372 KB Output is correct
6 Correct 4 ms 5372 KB Output is correct
7 Correct 5 ms 5372 KB Output is correct
8 Correct 5 ms 5372 KB Output is correct
9 Correct 5 ms 5372 KB Output is correct
10 Correct 5 ms 5372 KB Output is correct
11 Correct 5 ms 5372 KB Output is correct
12 Correct 6 ms 5372 KB Output is correct
13 Correct 5 ms 5372 KB Output is correct
14 Correct 5 ms 5372 KB Output is correct
15 Correct 5 ms 5372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5372 KB Output is correct
2 Correct 5 ms 5372 KB Output is correct
3 Correct 5 ms 5372 KB Output is correct
4 Correct 5 ms 5372 KB Output is correct
5 Correct 6 ms 5372 KB Output is correct
6 Correct 5 ms 5372 KB Output is correct
7 Correct 4 ms 5372 KB Output is correct
8 Correct 5 ms 5372 KB Output is correct
9 Correct 6 ms 5372 KB Output is correct
10 Correct 7 ms 5372 KB Output is correct
11 Correct 7 ms 5372 KB Output is correct
12 Correct 8 ms 5372 KB Output is correct
13 Correct 5 ms 5372 KB Output is correct
14 Correct 6 ms 5372 KB Output is correct
15 Correct 6 ms 5372 KB Output is correct
16 Correct 6 ms 5372 KB Output is correct
17 Correct 6 ms 5372 KB Output is correct
18 Correct 5 ms 5372 KB Output is correct
19 Correct 5 ms 5372 KB Output is correct
20 Correct 5 ms 5372 KB Output is correct
21 Correct 5 ms 5372 KB Output is correct
22 Correct 5 ms 5372 KB Output is correct
23 Correct 6 ms 5372 KB Output is correct
24 Correct 7 ms 5372 KB Output is correct
25 Correct 7 ms 5372 KB Output is correct
26 Correct 15 ms 5372 KB Output is correct
27 Correct 15 ms 5380 KB Output is correct
28 Correct 6 ms 5380 KB Output is correct
29 Correct 9 ms 5380 KB Output is correct
30 Correct 6 ms 5380 KB Output is correct
31 Correct 7 ms 5380 KB Output is correct
32 Correct 6 ms 5380 KB Output is correct
33 Correct 11 ms 5380 KB Output is correct
34 Correct 13 ms 5484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5484 KB Output is correct
2 Correct 5 ms 5484 KB Output is correct
3 Correct 5 ms 5484 KB Output is correct
4 Correct 6 ms 5484 KB Output is correct
5 Correct 5 ms 5484 KB Output is correct
6 Correct 6 ms 5484 KB Output is correct
7 Correct 6 ms 5484 KB Output is correct
8 Correct 5 ms 5484 KB Output is correct
9 Correct 5 ms 5484 KB Output is correct
10 Correct 5 ms 5484 KB Output is correct
11 Correct 5 ms 5484 KB Output is correct
12 Correct 6 ms 5484 KB Output is correct
13 Correct 5 ms 5484 KB Output is correct
14 Correct 5 ms 5484 KB Output is correct
15 Correct 5 ms 5484 KB Output is correct
16 Correct 5 ms 5484 KB Output is correct
17 Correct 6 ms 5484 KB Output is correct
18 Correct 5 ms 5484 KB Output is correct
19 Correct 6 ms 5484 KB Output is correct
20 Correct 7 ms 5484 KB Output is correct
21 Correct 6 ms 5484 KB Output is correct
22 Correct 6 ms 5484 KB Output is correct
23 Correct 6 ms 5484 KB Output is correct
24 Correct 6 ms 5484 KB Output is correct
25 Correct 7 ms 5484 KB Output is correct
26 Correct 15 ms 5484 KB Output is correct
27 Correct 21 ms 5484 KB Output is correct
28 Correct 6 ms 5484 KB Output is correct
29 Correct 10 ms 5484 KB Output is correct
30 Correct 6 ms 5484 KB Output is correct
31 Correct 7 ms 5484 KB Output is correct
32 Correct 6 ms 5484 KB Output is correct
33 Correct 16 ms 5484 KB Output is correct
34 Correct 12 ms 5484 KB Output is correct
35 Correct 15 ms 5484 KB Output is correct
36 Correct 7 ms 5484 KB Output is correct
37 Correct 18 ms 5520 KB Output is correct
38 Correct 19 ms 5612 KB Output is correct
39 Correct 20 ms 5612 KB Output is correct
40 Correct 19 ms 5612 KB Output is correct
41 Correct 19 ms 5632 KB Output is correct
42 Correct 160 ms 5632 KB Output is correct
43 Correct 162 ms 5632 KB Output is correct
44 Correct 13 ms 5632 KB Output is correct
45 Correct 19 ms 5632 KB Output is correct
46 Correct 20 ms 5632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5632 KB Output is correct
2 Correct 5 ms 5632 KB Output is correct
3 Correct 5 ms 5632 KB Output is correct
4 Correct 5 ms 5632 KB Output is correct
5 Correct 5 ms 5632 KB Output is correct
6 Correct 5 ms 5632 KB Output is correct
7 Correct 5 ms 5632 KB Output is correct
8 Correct 5 ms 5632 KB Output is correct
9 Correct 6 ms 5632 KB Output is correct
10 Correct 5 ms 5632 KB Output is correct
11 Correct 5 ms 5632 KB Output is correct
12 Correct 6 ms 5632 KB Output is correct
13 Correct 5 ms 5632 KB Output is correct
14 Correct 5 ms 5632 KB Output is correct
15 Correct 5 ms 5632 KB Output is correct
16 Correct 5 ms 5632 KB Output is correct
17 Correct 6 ms 5632 KB Output is correct
18 Correct 5 ms 5632 KB Output is correct
19 Correct 5 ms 5632 KB Output is correct
20 Correct 6 ms 5632 KB Output is correct
21 Correct 5 ms 5632 KB Output is correct
22 Correct 5 ms 5632 KB Output is correct
23 Correct 6 ms 5632 KB Output is correct
24 Correct 6 ms 5632 KB Output is correct
25 Correct 6 ms 5632 KB Output is correct
26 Correct 15 ms 5632 KB Output is correct
27 Correct 14 ms 5632 KB Output is correct
28 Correct 6 ms 5632 KB Output is correct
29 Correct 9 ms 5632 KB Output is correct
30 Correct 6 ms 5632 KB Output is correct
31 Correct 7 ms 5632 KB Output is correct
32 Correct 6 ms 5632 KB Output is correct
33 Correct 12 ms 5632 KB Output is correct
34 Correct 16 ms 5632 KB Output is correct
35 Correct 16 ms 5632 KB Output is correct
36 Correct 7 ms 5632 KB Output is correct
37 Correct 16 ms 5632 KB Output is correct
38 Correct 19 ms 5632 KB Output is correct
39 Correct 20 ms 5632 KB Output is correct
40 Correct 19 ms 5632 KB Output is correct
41 Correct 19 ms 5632 KB Output is correct
42 Correct 174 ms 5632 KB Output is correct
43 Correct 182 ms 5632 KB Output is correct
44 Correct 12 ms 5632 KB Output is correct
45 Correct 21 ms 5632 KB Output is correct
46 Correct 20 ms 5632 KB Output is correct
47 Correct 57 ms 6192 KB Output is correct
48 Correct 18 ms 6192 KB Output is correct
49 Correct 13 ms 6192 KB Output is correct
50 Correct 10 ms 6192 KB Output is correct
51 Correct 69 ms 7404 KB Output is correct
52 Correct 74 ms 7404 KB Output is correct
53 Correct 31 ms 7404 KB Output is correct
54 Correct 9 ms 7404 KB Output is correct
55 Correct 11 ms 7404 KB Output is correct
56 Correct 16 ms 7404 KB Output is correct
57 Correct 66 ms 7404 KB Output is correct
58 Execution timed out 1075 ms 7404 KB Time limit exceeded
59 Halted 0 ms 0 KB -