Submission #895818

#TimeUsernameProblemLanguageResultExecution timeMemory
895818tvladm2009Exam (eJOI20_exam)C++17
0 / 100
5 ms600 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n + 1), b(n + 1), r(n + 1); map<int, int> pos; for (int i = 1; i <= n; ++i) { cin >> a[i]; pos[a[i]] = i; } for (int i = 1; i <= n; ++i) { cin >> b[i]; } for (int i = n; i >= 1; --i) { r[i] = pos[b[i]]; } vector<int> dp(n + 1, 0); for (int i = n; i >= 1; --i) { if (r[i] == 0) { dp[i] = dp[i + 1]; continue; } int ans = 0; for (int j = i; j <= r[i]; ++j) ans += b[j] == b[i]; dp[i] = max(dp[i + 1], dp[r[i] + 1] + ans); } cout << dp[1] << endl; return 0; }
#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...