제출 #1127406

#제출 시각아이디문제언어결과실행 시간메모리
1127406khanhphucscratchExam (eJOI20_exam)C++20
0 / 100
1095 ms8332 KiB
//n <= 100 #include<bits/stdc++.h> using namespace std; int dp[5005][5005], a[5005], b[5005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin>>n; for(int i = 1; i <= n; i++) cin>>a[i]; for(int i = 1; i <= n; i++) cin>>b[i]; int curmaxa = 0; for(int i = 1; i <= n; i++){ curmaxa = max(curmaxa, a[i]); if(a[i] == curmaxa) dp[0][i] = 0; else dp[0][i] = -1e9; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ int curmax = 0; for(int k = j; k >= 1; k--){ curmax = max(curmax, a[k]); if(curmax == a[k] || curmax == a[j]) dp[i][j] = max(dp[i][j], dp[i-1][k]); } if(b[i] == a[j]) dp[i][j]++; } } int ans = 0, curmax = 0; for(int i = n; i >= 1; i--){ curmax = max(curmax, a[i]); if(a[i] == curmax) ans = max(ans, dp[n][i]); } cout<<ans; }
#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...