Submission #839799

#TimeUsernameProblemLanguageResultExecution timeMemory
839799tshabanov7Exam (eJOI20_exam)C++17
12 / 100
16 ms1108 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } if (count(b.begin(), b.end(), b[0]) == n) { int ans = 0; for (int i = 0; i < n; i++) { if (a[i] > b[0]) { continue; } bool ok = false; int j = i; while (j < n && a[j] <= b[0]) { ok |= a[j] == b[0]; j++; } if (ok) { ans += j - i; } i = j - 1; } cout << ans << '\n'; return 0; } if (is_sorted(a.begin(), a.end())) { vector<int> dp(n + 1); for (int i = 0; i < n; i++) { int cnt = 0; for (int j = i; j >= 0; j--) { cnt += b[j] == a[i]; dp[i + 1] = max(dp[i + 1], dp[j] + cnt); } } cout << dp[n] << '\n'; return 0; } 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...