Submission #887653

# Submission time Handle Problem Language Result Execution time Memory
887653 2023-12-15T00:15:59 Z TAhmed33 Sightseeing in Kyoto (JOI22_kyoto) C++
40 / 100
1245 ms 158512 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 25;
typedef long long ll;
ll n, m, a[MAXN], b[MAXN];
ll mnp[MAXN][2], mns[MAXN][2];
vector <ll> remx = {0}, remy = {0};
ll dp[3001][3001];
int main () {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		mnp[i][0] = mns[i][0] = a[i];
	}
	for (int i = 1; i <= m; i++) {
		cin >> b[i];
		mnp[i][1] = mns[i][1] = b[i];
	}
	for (int i = 2; i <= n; i++) {
		mnp[i][0] = min(mnp[i][0], mnp[i - 1][0]);
	}
	for (int i = 2; i <= m; i++) {
		mnp[i][1] = min(mnp[i][1], mnp[i - 1][1]);
	}
	for (int i = n - 1; i >= 1; i--) {
		mns[i][0] = min(mns[i][0], mns[i + 1][0]);
	}
	for (int i = m - 1; i >= 1; i--) {
		mns[i][1] = min(mns[i][1], mns[i + 1][1]);
	}
	for (int i = 1; i <= n; i++) {
		bool flag = i > 1 && a[i] >= mnp[i - 1][0];
		flag &= i < n && a[i] >= mns[i + 1][0];
		if (flag) continue;
		remx.push_back(i);
	}
	for (int i = 1; i <= m; i++) {
		bool flag = i > 1 && b[i] >= mnp[i - 1][1];
		flag &= i < m && b[i] >= mns[i + 1][1];
		if (flag) continue;
		remy.push_back(i);
	}
	for (int i = 1; i < (int)remx.size(); i++) {
		for (int j = 1; j < (int)remy.size(); j++) {
			if (i == j && j == 1) continue;
			dp[i][j] = 1e18;
			if (i > 1) dp[i][j] = min(dp[i][j], dp[i - 1][j] + b[remy[j]] * (remx[i] - remx[i - 1]));
			if (j > 1) dp[i][j] = min(dp[i][j], dp[i][j - 1] + a[remx[i]] * (remy[j] - remy[j - 1]));
		}
	}
	cout << dp[(int)remx.size() - 1][(int)remy.size() - 1] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 7 ms 29272 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 7 ms 29244 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 3 ms 12636 KB Output is correct
4 Correct 13 ms 13660 KB Output is correct
5 Correct 13 ms 9052 KB Output is correct
6 Correct 6 ms 6820 KB Output is correct
7 Correct 30 ms 8384 KB Output is correct
8 Correct 30 ms 8372 KB Output is correct
9 Correct 31 ms 14676 KB Output is correct
10 Correct 32 ms 16556 KB Output is correct
11 Correct 50 ms 53760 KB Output is correct
12 Correct 32 ms 16724 KB Output is correct
13 Correct 34 ms 16724 KB Output is correct
14 Correct 48 ms 53684 KB Output is correct
15 Correct 36 ms 6484 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4600 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 7 ms 29272 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 7 ms 29244 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 3 ms 12636 KB Output is correct
32 Correct 13 ms 13660 KB Output is correct
33 Correct 13 ms 9052 KB Output is correct
34 Correct 6 ms 6820 KB Output is correct
35 Correct 30 ms 8384 KB Output is correct
36 Correct 30 ms 8372 KB Output is correct
37 Correct 31 ms 14676 KB Output is correct
38 Correct 32 ms 16556 KB Output is correct
39 Correct 50 ms 53760 KB Output is correct
40 Correct 32 ms 16724 KB Output is correct
41 Correct 34 ms 16724 KB Output is correct
42 Correct 48 ms 53684 KB Output is correct
43 Correct 36 ms 6484 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4440 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4600 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 26 ms 8084 KB Output is correct
56 Correct 2 ms 6492 KB Output is correct
57 Correct 4 ms 8792 KB Output is correct
58 Correct 9 ms 11096 KB Output is correct
59 Correct 57 ms 9536 KB Output is correct
60 Correct 57 ms 9556 KB Output is correct
61 Correct 58 ms 17880 KB Output is correct
62 Correct 59 ms 17744 KB Output is correct
63 Runtime error 1245 ms 158512 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -