Submission #821081

#TimeUsernameProblemLanguageResultExecution timeMemory
821081PVM_pvmSightseeing in Kyoto (JOI22_kyoto)C++17
10 / 100
13 ms8352 KiB
#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";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...