Submission #556890

# Submission time Handle Problem Language Result Execution time Memory
556890 2022-05-04T09:59:17 Z DanShaders Sightseeing in Kyoto (JOI22_kyoto) C++17
40 / 100
497 ms 71016 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;

template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;

#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;

#define int ll

const int N = 1e5 + 10, M = 2010, INF = 0x3f3f3f3f3f3f3f3f;

int suff[N];

int eliminate(int *a, int n, pair<int, int> *b) {
	suff[n] = +INF;
	for (int i = n; i--; ) {
		suff[i] = min(suff[i + 1], a[i]);
	}
	int mn = +INF, m = 0;
	for (int i = 0; i < n; ++i) {
		if (mn <= a[i] && suff[i + 1] <= a[i]) {
			continue;
		}
		mn = min(mn, a[i]);
		b[m++] = {a[i], i};
	}
	return m;
}

int a[N], b[N];
pair<int, int> c[M], d[M];
int dp[M][M];

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < m; ++i) {
		cin >> b[i];
	}
	n = eliminate(a, n, c);
	m = eliminate(b, m, d);

	fill(dp[0], dp[M], +INF);
	dp[0][0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + d[j].x * (c[i + 1].y - c[i].y));
			dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + c[i].x * (d[j + 1].y - d[j].y));
		}
	}
	cout << dp[n - 1][m - 1];
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 32000 KB Output is correct
2 Correct 12 ms 31912 KB Output is correct
3 Correct 13 ms 31956 KB Output is correct
4 Correct 13 ms 31960 KB Output is correct
5 Correct 13 ms 31968 KB Output is correct
6 Correct 13 ms 31956 KB Output is correct
7 Correct 14 ms 31956 KB Output is correct
8 Correct 14 ms 31956 KB Output is correct
9 Correct 18 ms 31956 KB Output is correct
10 Correct 14 ms 31956 KB Output is correct
11 Correct 14 ms 31956 KB Output is correct
12 Correct 14 ms 31956 KB Output is correct
13 Correct 18 ms 32032 KB Output is correct
14 Correct 13 ms 31932 KB Output is correct
15 Correct 13 ms 31988 KB Output is correct
16 Correct 17 ms 32024 KB Output is correct
17 Correct 13 ms 31904 KB Output is correct
18 Correct 16 ms 31876 KB Output is correct
19 Correct 14 ms 31956 KB Output is correct
20 Correct 13 ms 31956 KB Output is correct
21 Correct 13 ms 31908 KB Output is correct
22 Correct 14 ms 31956 KB Output is correct
23 Correct 14 ms 31956 KB Output is correct
24 Correct 15 ms 31956 KB Output is correct
25 Correct 14 ms 31956 KB Output is correct
26 Correct 13 ms 31904 KB Output is correct
27 Correct 13 ms 31932 KB Output is correct
28 Correct 13 ms 31860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 31896 KB Output is correct
2 Correct 13 ms 31912 KB Output is correct
3 Correct 15 ms 31956 KB Output is correct
4 Correct 21 ms 33108 KB Output is correct
5 Correct 20 ms 33356 KB Output is correct
6 Correct 20 ms 32572 KB Output is correct
7 Correct 39 ms 34968 KB Output is correct
8 Correct 30 ms 34912 KB Output is correct
9 Correct 29 ms 35020 KB Output is correct
10 Correct 27 ms 34864 KB Output is correct
11 Correct 42 ms 34892 KB Output is correct
12 Correct 28 ms 34980 KB Output is correct
13 Correct 37 ms 35020 KB Output is correct
14 Correct 47 ms 34988 KB Output is correct
15 Correct 33 ms 35068 KB Output is correct
16 Correct 15 ms 32032 KB Output is correct
17 Correct 13 ms 31956 KB Output is correct
18 Correct 14 ms 31956 KB Output is correct
19 Correct 14 ms 31956 KB Output is correct
20 Correct 16 ms 31956 KB Output is correct
21 Correct 15 ms 31928 KB Output is correct
22 Correct 14 ms 31948 KB Output is correct
23 Correct 15 ms 31956 KB Output is correct
24 Correct 14 ms 31956 KB Output is correct
25 Correct 14 ms 31860 KB Output is correct
26 Correct 16 ms 31956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 32000 KB Output is correct
2 Correct 12 ms 31912 KB Output is correct
3 Correct 13 ms 31956 KB Output is correct
4 Correct 13 ms 31960 KB Output is correct
5 Correct 13 ms 31968 KB Output is correct
6 Correct 13 ms 31956 KB Output is correct
7 Correct 14 ms 31956 KB Output is correct
8 Correct 14 ms 31956 KB Output is correct
9 Correct 18 ms 31956 KB Output is correct
10 Correct 14 ms 31956 KB Output is correct
11 Correct 14 ms 31956 KB Output is correct
12 Correct 14 ms 31956 KB Output is correct
13 Correct 18 ms 32032 KB Output is correct
14 Correct 13 ms 31932 KB Output is correct
15 Correct 13 ms 31988 KB Output is correct
16 Correct 17 ms 32024 KB Output is correct
17 Correct 13 ms 31904 KB Output is correct
18 Correct 16 ms 31876 KB Output is correct
19 Correct 14 ms 31956 KB Output is correct
20 Correct 13 ms 31956 KB Output is correct
21 Correct 13 ms 31908 KB Output is correct
22 Correct 14 ms 31956 KB Output is correct
23 Correct 14 ms 31956 KB Output is correct
24 Correct 15 ms 31956 KB Output is correct
25 Correct 14 ms 31956 KB Output is correct
26 Correct 13 ms 31904 KB Output is correct
27 Correct 13 ms 31932 KB Output is correct
28 Correct 13 ms 31860 KB Output is correct
29 Correct 14 ms 31896 KB Output is correct
30 Correct 13 ms 31912 KB Output is correct
31 Correct 15 ms 31956 KB Output is correct
32 Correct 21 ms 33108 KB Output is correct
33 Correct 20 ms 33356 KB Output is correct
34 Correct 20 ms 32572 KB Output is correct
35 Correct 39 ms 34968 KB Output is correct
36 Correct 30 ms 34912 KB Output is correct
37 Correct 29 ms 35020 KB Output is correct
38 Correct 27 ms 34864 KB Output is correct
39 Correct 42 ms 34892 KB Output is correct
40 Correct 28 ms 34980 KB Output is correct
41 Correct 37 ms 35020 KB Output is correct
42 Correct 47 ms 34988 KB Output is correct
43 Correct 33 ms 35068 KB Output is correct
44 Correct 15 ms 32032 KB Output is correct
45 Correct 13 ms 31956 KB Output is correct
46 Correct 14 ms 31956 KB Output is correct
47 Correct 14 ms 31956 KB Output is correct
48 Correct 16 ms 31956 KB Output is correct
49 Correct 15 ms 31928 KB Output is correct
50 Correct 14 ms 31948 KB Output is correct
51 Correct 15 ms 31956 KB Output is correct
52 Correct 14 ms 31956 KB Output is correct
53 Correct 14 ms 31860 KB Output is correct
54 Correct 16 ms 31956 KB Output is correct
55 Correct 22 ms 34072 KB Output is correct
56 Correct 13 ms 31920 KB Output is correct
57 Correct 15 ms 32080 KB Output is correct
58 Correct 17 ms 32452 KB Output is correct
59 Correct 43 ms 35992 KB Output is correct
60 Correct 34 ms 35780 KB Output is correct
61 Correct 35 ms 35812 KB Output is correct
62 Correct 36 ms 35964 KB Output is correct
63 Runtime error 497 ms 71016 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -