이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 5002;
int op[N][N]; //op[L][R] = number of (Hi == Ti) where (L ≤ i ≤ R) if we change H[L..R] to max(H[L..R])
int dp[N];
int n;
vector<int>h, t;
void solve24(){
cout << "hehe" << endl;
}
int f(int i){
if(i > n) return 0;
int &cur = dp[i];
if(cur != -1) return cur;
cur = f(i + 1) + (h[i] == t[i]); //skip i
for(int j = i + 1; j <= n; j++){
cur = max(cur, op[i][j] + f(j + 1));
}
return cur;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
h.resize(n + 1);
t.resize(n + 1);
for(int i = 1; i <= n; i++) cin >> h[i];
for(int i = 1; i <= n; i++) cin >> t[i];
if(n > 5000){
solve24();
return 0;
}
memset(dp, -1, sizeof(dp));
for(int i = 1; i <= n; i++){
map<int, int>freq;
freq[t[i]]++;
int maxi = h[i];
for(int j = i + 1; j <= n; j++){
freq[t[j]]++;
maxi = max(maxi, h[j]);
op[i][j] = freq[maxi];
}
}
cout << f(1) << '\n';
return 0;
}
# | 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... |