제출 #670527

#제출 시각아이디문제언어결과실행 시간메모리
670527someoneExam (eJOI20_exam)C++14
0 / 100
301 ms315076 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...