#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));
#define mod 1000000007
inline int add(int a,int b){
int r=a+b;
while(r>=mod)r-=mod;
while(r<0)r+=mod;
return r;
}
inline int mult(int a,int b){
return (int)(((ll)(a*b))%mod);
}
inline int rd(){
int x=0;
char ch=getchar_unlocked();
while(!(ch&16))ch=getchar();//keep reading while current character is whitespace
while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
x=(x<<3)+(x<<1)+(ch&15);
ch=getchar_unlocked();
}
return x;
}
#define maxn 1005
int h,w,a[maxn],b[maxn];
ll memo[maxn][maxn];
ll dp(int i,int j){
if(i==h&&j==w)return 0;
if(i>h||j>w)return LINF;
if(memo[i][j]!=-1)return memo[i][j];
return memo[i][j]=min(dp(i+1,j)+b[j],dp(i,j+1)+a[i]);
}
int main(){
sf("%d%d",&h,&w);
for(int i=1;i<=h;++i)sf("%d",&a[i]);
for(int i=1;i<=w;++i)sf("%d",&b[i]);
memset(memo,-1,sizeof memo);
/*
for(int i=1;i<=h;++i){
for(int j=1;j<=w;++j){
pf("%3d ",dp(i,j));
}
pf("\n");
}
*/
pf("%lld\n",dp(1,1));
}
Compilation message
kyoto.cpp: In function 'int main()':
kyoto.cpp:70:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | sf("%d%d",&h,&w);
| ^
kyoto.cpp:71:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | for(int i=1;i<=h;++i)sf("%d",&a[i]);
| ^
kyoto.cpp:72:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | for(int i=1;i<=w;++i)sf("%d",&b[i]);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8148 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
7 ms |
8276 KB |
Output is correct |
5 |
Correct |
4 ms |
8252 KB |
Output is correct |
6 |
Correct |
4 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
4 ms |
8148 KB |
Output is correct |
9 |
Correct |
15 ms |
8264 KB |
Output is correct |
10 |
Correct |
16 ms |
8276 KB |
Output is correct |
11 |
Correct |
17 ms |
8276 KB |
Output is correct |
12 |
Correct |
16 ms |
8276 KB |
Output is correct |
13 |
Correct |
16 ms |
8352 KB |
Output is correct |
14 |
Correct |
17 ms |
8276 KB |
Output is correct |
15 |
Correct |
16 ms |
8268 KB |
Output is correct |
16 |
Correct |
17 ms |
8272 KB |
Output is correct |
17 |
Correct |
16 ms |
8276 KB |
Output is correct |
18 |
Correct |
4 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8148 KB |
Output is correct |
20 |
Correct |
4 ms |
8124 KB |
Output is correct |
21 |
Correct |
4 ms |
8148 KB |
Output is correct |
22 |
Correct |
4 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8148 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
3 ms |
8116 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
27 |
Correct |
4 ms |
8124 KB |
Output is correct |
28 |
Correct |
3 ms |
8148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Incorrect |
7 ms |
8276 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8148 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
7 ms |
8276 KB |
Output is correct |
5 |
Correct |
4 ms |
8252 KB |
Output is correct |
6 |
Correct |
4 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
4 ms |
8148 KB |
Output is correct |
9 |
Correct |
15 ms |
8264 KB |
Output is correct |
10 |
Correct |
16 ms |
8276 KB |
Output is correct |
11 |
Correct |
17 ms |
8276 KB |
Output is correct |
12 |
Correct |
16 ms |
8276 KB |
Output is correct |
13 |
Correct |
16 ms |
8352 KB |
Output is correct |
14 |
Correct |
17 ms |
8276 KB |
Output is correct |
15 |
Correct |
16 ms |
8268 KB |
Output is correct |
16 |
Correct |
17 ms |
8272 KB |
Output is correct |
17 |
Correct |
16 ms |
8276 KB |
Output is correct |
18 |
Correct |
4 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8148 KB |
Output is correct |
20 |
Correct |
4 ms |
8124 KB |
Output is correct |
21 |
Correct |
4 ms |
8148 KB |
Output is correct |
22 |
Correct |
4 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8148 KB |
Output is correct |
24 |
Correct |
4 ms |
8148 KB |
Output is correct |
25 |
Correct |
3 ms |
8116 KB |
Output is correct |
26 |
Correct |
4 ms |
8148 KB |
Output is correct |
27 |
Correct |
4 ms |
8124 KB |
Output is correct |
28 |
Correct |
3 ms |
8148 KB |
Output is correct |
29 |
Correct |
4 ms |
8148 KB |
Output is correct |
30 |
Correct |
4 ms |
8148 KB |
Output is correct |
31 |
Incorrect |
7 ms |
8276 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |