#include<bits/stdc++.h>
using namespace std;
#define MAXX 1007
long long dp[MAXX][MAXX];
long long a[MAXX],b[MAXX];
int h,w;
long long fun(int h1,int w1)
{
if (h1==1 && w1==1) return 0;
if (dp[h1][w1]!=0) return dp[h1][w1];
if (h1==1)
{
dp[h1][w1]=fun(h1,w1-1)+a[h1];
return dp[h1][w1];
}
if (w1==1)
{
dp[h1][w1]=fun(h1-1,w1)+b[w1];
return dp[h1][w1];
}
dp[h1][w1]=min(fun(h1,w1-1)+a[h1],fun(h1-1,w1)+b[w1]);
return dp[h1][w1];
}
int main()
{
cin>>h>>w;
for (int q=1;q<=h;q++) cin>>a[q];
for (int q=1;q<=w;q++) cin>>b[q];
cout<<fun(h,w)<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
820 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
10 ms |
8276 KB |
Output is correct |
10 |
Correct |
10 ms |
8352 KB |
Output is correct |
11 |
Correct |
10 ms |
8308 KB |
Output is correct |
12 |
Correct |
10 ms |
8304 KB |
Output is correct |
13 |
Correct |
9 ms |
8276 KB |
Output is correct |
14 |
Correct |
10 ms |
8252 KB |
Output is correct |
15 |
Correct |
13 ms |
8300 KB |
Output is correct |
16 |
Correct |
9 ms |
8260 KB |
Output is correct |
17 |
Correct |
10 ms |
8276 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
3 ms |
2772 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
820 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
10 ms |
8276 KB |
Output is correct |
10 |
Correct |
10 ms |
8352 KB |
Output is correct |
11 |
Correct |
10 ms |
8308 KB |
Output is correct |
12 |
Correct |
10 ms |
8304 KB |
Output is correct |
13 |
Correct |
9 ms |
8276 KB |
Output is correct |
14 |
Correct |
10 ms |
8252 KB |
Output is correct |
15 |
Correct |
13 ms |
8300 KB |
Output is correct |
16 |
Correct |
9 ms |
8260 KB |
Output is correct |
17 |
Correct |
10 ms |
8276 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Incorrect |
3 ms |
2772 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |