#include <bits/stdc++.h>
using namespace std;
//ofstream fout("date.out");
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
typedef long long ll;
const ll INF=1e17;
ll n,m;
ll lin[100005],col[100005],dp[1005][1005];
ll from[1005][1005];
string dig(ll x)
{
string s;
while(x!=0)
{
s.push_back(char('0'+x%10));
x/=10;
}
while(s.size()<4)
s.push_back('0');
reverse(s.begin(),s.end());
return s;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>lin[i];
for(int i=1;i<=m;i++)
cin>>col[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(i!=1||j!=1)
{
dp[i][j]=INF;
if(i>1&&dp[i-1][j]+col[j]<dp[i][j])
{
dp[i][j]=min(dp[i][j],dp[i-1][j]+col[j]);
from[i][j]=1;
}
if(j>1&&dp[i][j-1]+lin[i]<dp[i][j])
{
dp[i][j]=min(dp[i][j],dp[i][j-1]+lin[i]);
from[i][j]=2;
}
}
cout<<dp[n][m];
int i=n,j=m;
int prv=0;
int changes=0;
while(i!=1||j!=1)
{
if(from[i][j]!=prv&&prv!=0)
changes++;
prv=from[i][j];
if(from[i][j]==1)
i--;
else
j--;
}
assert(changes<=600);
return 0;
}
# |
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 |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
2 ms |
12636 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
7 ms |
17060 KB |
Output is correct |
10 |
Correct |
7 ms |
16984 KB |
Output is correct |
11 |
Correct |
7 ms |
16984 KB |
Output is correct |
12 |
Correct |
8 ms |
16988 KB |
Output is correct |
13 |
Correct |
4 ms |
16988 KB |
Output is correct |
14 |
Correct |
7 ms |
16984 KB |
Output is correct |
15 |
Correct |
7 ms |
17240 KB |
Output is correct |
16 |
Correct |
5 ms |
16988 KB |
Output is correct |
17 |
Correct |
4 ms |
16988 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 |
4528 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 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 |
4440 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 |
Runtime error |
10 ms |
21596 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
12636 KB |
Output is correct |
6 |
Correct |
2 ms |
12636 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
7 ms |
17060 KB |
Output is correct |
10 |
Correct |
7 ms |
16984 KB |
Output is correct |
11 |
Correct |
7 ms |
16984 KB |
Output is correct |
12 |
Correct |
8 ms |
16988 KB |
Output is correct |
13 |
Correct |
4 ms |
16988 KB |
Output is correct |
14 |
Correct |
7 ms |
16984 KB |
Output is correct |
15 |
Correct |
7 ms |
17240 KB |
Output is correct |
16 |
Correct |
5 ms |
16988 KB |
Output is correct |
17 |
Correct |
4 ms |
16988 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 |
4528 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4440 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 |
4440 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Runtime error |
10 ms |
21596 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |