Submission #41453

# Submission time Handle Problem Language Result Execution time Memory
41453 2018-02-17T08:59:23 Z cmaster Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
330 ms 33492 KB
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/
 
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(false); cin.tie(0) 
#define F first
#define S second
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)5e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int n, m, b[MAXN], p[MAXN], d[2020];
vector < pair < int, int > > g[2020];
vector < int > divs[2020], have[2020];

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	onlycin;
	cin >> n >> m;
	rep(i, 1, m) {
		cin >> b[i] >> p[i];
		have[++b[i]].pb(p[i]);
	}
	rep(i, 1, n) {
		sort(all(have[i])); have[i].resize(unique(all(have[i]))-have[i].begin());
	}
	rep(i, 1, n) {
		for(int j = i; j <= n; j += i) divs[j].pb(i);
	}
	rep(i, 1, n) {
		rep(j, 1, n) {
			if(i == j) continue;
			int cost = 202020;
			for(auto &to : divs[abs(i-j)]) {
				if(binary_search(all(have[i]), to)) updmin(cost, abs(i-j)/to);
			}
			if(cost < 202020) g[i].pb(mp(j, cost));
		}
	}
	memset(d, 0x3f, sizeof d);
	d[b[1]] = 0;
	set < pair < int, int > > S; S.insert(mp(0, b[1]));
	while(!S.empty()) {
		int v = S.begin()->second;
		S.erase(S.begin());
		for(auto &it : g[v]) {
			int cost = it.S, to = it.F;
			if(d[to] > d[v]+cost) {
				S.erase(mp(d[to], to));
				d[to] = d[v]+cost;
				S.insert(mp(d[to], to));
			}
		}
	}
	if(d[b[2]] == d[0]) d[b[2]] = -1;
	cout << d[b[2]] << nxtl;
	
	return 0;
}
# 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 1 ms 568 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 2 ms 608 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 608 KB Output is correct
2 Correct 1 ms 660 KB Output is correct
3 Correct 1 ms 660 KB Output is correct
4 Correct 1 ms 676 KB Output is correct
5 Correct 1 ms 760 KB Output is correct
6 Correct 1 ms 760 KB Output is correct
7 Correct 1 ms 760 KB Output is correct
8 Correct 1 ms 760 KB Output is correct
9 Correct 2 ms 780 KB Output is correct
10 Correct 2 ms 780 KB Output is correct
11 Correct 4 ms 832 KB Output is correct
12 Correct 2 ms 832 KB Output is correct
13 Correct 2 ms 832 KB Output is correct
14 Correct 2 ms 900 KB Output is correct
15 Correct 3 ms 900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 900 KB Output is correct
2 Correct 1 ms 900 KB Output is correct
3 Correct 2 ms 900 KB Output is correct
4 Correct 1 ms 900 KB Output is correct
5 Correct 1 ms 900 KB Output is correct
6 Correct 1 ms 900 KB Output is correct
7 Correct 2 ms 900 KB Output is correct
8 Correct 2 ms 900 KB Output is correct
9 Correct 2 ms 900 KB Output is correct
10 Correct 2 ms 900 KB Output is correct
11 Correct 3 ms 900 KB Output is correct
12 Correct 2 ms 900 KB Output is correct
13 Correct 2 ms 924 KB Output is correct
14 Correct 2 ms 924 KB Output is correct
15 Correct 2 ms 924 KB Output is correct
16 Correct 4 ms 924 KB Output is correct
17 Correct 25 ms 1132 KB Output is correct
18 Correct 88 ms 1132 KB Output is correct
19 Correct 108 ms 1132 KB Output is correct
20 Correct 213 ms 33116 KB Output is correct
21 Correct 7 ms 33116 KB Output is correct
22 Correct 87 ms 33116 KB Output is correct
23 Correct 75 ms 33116 KB Output is correct
24 Correct 127 ms 33116 KB Output is correct
25 Correct 128 ms 33116 KB Output is correct
26 Correct 101 ms 33116 KB Output is correct
27 Correct 98 ms 33116 KB Output is correct
28 Correct 144 ms 33116 KB Output is correct
29 Correct 105 ms 33116 KB Output is correct
30 Correct 99 ms 33116 KB Output is correct
31 Correct 121 ms 33116 KB Output is correct
32 Correct 104 ms 33116 KB Output is correct
33 Correct 110 ms 33116 KB Output is correct
34 Correct 120 ms 33116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 33116 KB Output is correct
2 Correct 2 ms 33116 KB Output is correct
3 Correct 1 ms 33116 KB Output is correct
4 Correct 1 ms 33116 KB Output is correct
5 Correct 2 ms 33116 KB Output is correct
6 Correct 2 ms 33116 KB Output is correct
7 Correct 1 ms 33116 KB Output is correct
8 Correct 2 ms 33116 KB Output is correct
9 Correct 2 ms 33116 KB Output is correct
10 Correct 2 ms 33116 KB Output is correct
11 Correct 3 ms 33116 KB Output is correct
12 Correct 2 ms 33116 KB Output is correct
13 Correct 2 ms 33116 KB Output is correct
14 Correct 2 ms 33116 KB Output is correct
15 Correct 2 ms 33116 KB Output is correct
16 Correct 4 ms 33116 KB Output is correct
17 Correct 26 ms 33116 KB Output is correct
18 Correct 90 ms 33116 KB Output is correct
19 Correct 120 ms 33116 KB Output is correct
20 Correct 214 ms 33188 KB Output is correct
21 Correct 7 ms 33188 KB Output is correct
22 Correct 92 ms 33188 KB Output is correct
23 Correct 78 ms 33188 KB Output is correct
24 Correct 128 ms 33188 KB Output is correct
25 Correct 130 ms 33188 KB Output is correct
26 Correct 102 ms 33188 KB Output is correct
27 Correct 106 ms 33188 KB Output is correct
28 Correct 144 ms 33188 KB Output is correct
29 Correct 121 ms 33188 KB Output is correct
30 Correct 107 ms 33188 KB Output is correct
31 Correct 104 ms 33188 KB Output is correct
32 Correct 108 ms 33188 KB Output is correct
33 Correct 109 ms 33188 KB Output is correct
34 Correct 128 ms 33188 KB Output is correct
35 Correct 163 ms 33188 KB Output is correct
36 Correct 60 ms 33188 KB Output is correct
37 Correct 282 ms 33188 KB Output is correct
38 Correct 312 ms 33188 KB Output is correct
39 Correct 314 ms 33188 KB Output is correct
40 Correct 318 ms 33188 KB Output is correct
41 Correct 320 ms 33188 KB Output is correct
42 Correct 105 ms 33188 KB Output is correct
43 Correct 107 ms 33188 KB Output is correct
44 Correct 216 ms 33492 KB Output is correct
45 Correct 169 ms 33492 KB Output is correct
46 Correct 170 ms 33492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 33492 KB Output is correct
2 Correct 2 ms 33492 KB Output is correct
3 Correct 2 ms 33492 KB Output is correct
4 Correct 1 ms 33492 KB Output is correct
5 Correct 1 ms 33492 KB Output is correct
6 Correct 2 ms 33492 KB Output is correct
7 Correct 2 ms 33492 KB Output is correct
8 Correct 2 ms 33492 KB Output is correct
9 Correct 2 ms 33492 KB Output is correct
10 Correct 2 ms 33492 KB Output is correct
11 Correct 3 ms 33492 KB Output is correct
12 Correct 2 ms 33492 KB Output is correct
13 Correct 3 ms 33492 KB Output is correct
14 Correct 3 ms 33492 KB Output is correct
15 Correct 2 ms 33492 KB Output is correct
16 Correct 4 ms 33492 KB Output is correct
17 Correct 25 ms 33492 KB Output is correct
18 Correct 89 ms 33492 KB Output is correct
19 Correct 111 ms 33492 KB Output is correct
20 Correct 208 ms 33492 KB Output is correct
21 Correct 7 ms 33492 KB Output is correct
22 Correct 97 ms 33492 KB Output is correct
23 Correct 86 ms 33492 KB Output is correct
24 Correct 130 ms 33492 KB Output is correct
25 Correct 138 ms 33492 KB Output is correct
26 Correct 103 ms 33492 KB Output is correct
27 Correct 101 ms 33492 KB Output is correct
28 Correct 145 ms 33492 KB Output is correct
29 Correct 106 ms 33492 KB Output is correct
30 Correct 101 ms 33492 KB Output is correct
31 Correct 106 ms 33492 KB Output is correct
32 Correct 106 ms 33492 KB Output is correct
33 Correct 115 ms 33492 KB Output is correct
34 Correct 113 ms 33492 KB Output is correct
35 Correct 163 ms 33492 KB Output is correct
36 Correct 58 ms 33492 KB Output is correct
37 Correct 292 ms 33492 KB Output is correct
38 Correct 313 ms 33492 KB Output is correct
39 Correct 315 ms 33492 KB Output is correct
40 Correct 319 ms 33492 KB Output is correct
41 Correct 330 ms 33492 KB Output is correct
42 Correct 108 ms 33492 KB Output is correct
43 Correct 109 ms 33492 KB Output is correct
44 Correct 213 ms 33492 KB Output is correct
45 Correct 177 ms 33492 KB Output is correct
46 Correct 162 ms 33492 KB Output is correct
47 Runtime error 3 ms 33492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Halted 0 ms 0 KB -