Submission #1127557

#TimeUsernameProblemLanguageResultExecution timeMemory
1127557khanhphucscratchExam (eJOI20_exam)C++20
30 / 100
1096 ms8316 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]++; } for(int j = 1; j <= n; j++){ int curmax = 0; for(int k = min(i, j); k <= max(i, j); k++) curmax = max(curmax, a[k]); if(curmax > a[j]) dp[i][j] = -1e9; } } 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...