답안 #765127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765127 2023-06-24T08:29:56 Z ymm Sightseeing in Kyoto (JOI22_kyoto) C++17
40 / 100
37 ms 39652 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 5050;
ll A[N], B[N];
ll cA[N], cB[N];
ll dp[N][N];
int n, m;

void input(int &n, ll *A, ll *cA)
{
	Loop (i,0,n) {
		cin >> A[i];
		while (i >= 2) {
			if (A[i-2] > A[i-1] || A[i-1] < A[i])
				break;
			A[i-1] = A[i];
			cA[i-2] += cA[i-1];
			--i;
			--n;
		}
		cA[i]=1;
	}
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n >> m;
	input(n, A, cA);
	input(m, B, cB);
	Loop (i,0,n) Loop (j,0,m) {
		if (!i && !j)
			continue;
		ll ans = LONG_LONG_MAX;
		if (i)
			ans = min(ans, dp[i-1][j] + B[j] * cA[i-1]);
		if (j)
			ans = min(ans, dp[i][j-1] + A[i] * cB[j-1]);
		dp[i][j] = ans;
	}
	cout << dp[n-1][m-1] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 276 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 9 ms 12244 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 9 ms 12244 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 3924 KB Output is correct
4 Correct 7 ms 1876 KB Output is correct
5 Correct 5 ms 2772 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 11 ms 348 KB Output is correct
8 Correct 11 ms 348 KB Output is correct
9 Correct 12 ms 2644 KB Output is correct
10 Correct 12 ms 2644 KB Output is correct
11 Correct 37 ms 39652 KB Output is correct
12 Correct 12 ms 3116 KB Output is correct
13 Correct 13 ms 3028 KB Output is correct
14 Correct 37 ms 39124 KB Output is correct
15 Correct 11 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 276 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 9 ms 12244 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 9 ms 12244 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 3 ms 3924 KB Output is correct
32 Correct 7 ms 1876 KB Output is correct
33 Correct 5 ms 2772 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 11 ms 348 KB Output is correct
36 Correct 11 ms 348 KB Output is correct
37 Correct 12 ms 2644 KB Output is correct
38 Correct 12 ms 2644 KB Output is correct
39 Correct 37 ms 39652 KB Output is correct
40 Correct 12 ms 3116 KB Output is correct
41 Correct 13 ms 3028 KB Output is correct
42 Correct 37 ms 39124 KB Output is correct
43 Correct 11 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 7 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 852 KB Output is correct
58 Correct 3 ms 1364 KB Output is correct
59 Correct 17 ms 336 KB Output is correct
60 Correct 19 ms 340 KB Output is correct
61 Correct 24 ms 3276 KB Output is correct
62 Correct 19 ms 3540 KB Output is correct
63 Runtime error 4 ms 596 KB Execution killed with signal 11
64 Halted 0 ms 0 KB -