제출 #765122

#제출 시각아이디문제언어결과실행 시간메모리
765122ymmSightseeing in Kyoto (JOI22_kyoto)C++17
40 / 100
34 ms32676 KiB
#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 = 2020; 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'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...