이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e3 + 42, INF = 1e18 + 42;
int n, a[N], b[N], nb[N][N], cost[N][N], dp[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < n; i++)
cin >> b[i];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++) {
nb[i][j+1] = nb[i][j];
if(a[i] == b[j])
nb[i][j+1]++;
}
for(int i = 0; i < n; i++) {
int imax = i;
for(int j = i+1; j <= n; j++) {
if(a[imax] < a[j-1])
imax = j-1;
cost[i][j] = nb[imax][j] - nb[imax][i];
}
}
for(int i = 1; i <= n; i++)
for(int j = 0; j < i; j++)
dp[i] = max(dp[i], dp[j] + cost[j][i]);
cout << dp[n];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |