Submission #425595

#TimeUsernameProblemLanguageResultExecution timeMemory
425595MilosMilutinovicExam (eJOI20_exam)C++14
12 / 100
1088 ms1112 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long unsigned long ull; typedef double long ld; int n, a[100050], b[100050]; void solve2() { for (int i = 1; i <= n; i++) { if (a[i] == b[i]) { for (int j = i + 1; j <= n; j++) { if (a[j] >= a[i]) { break; } a[j] = a[i]; } for (int j = i - 1; j >= 1; j--) { if (a[j] >= a[i]) { break; } a[j] = a[i]; } } } int ans = 0; for (int i = 1; i <= n; i++) { ans += (a[i] == b[i] ? 1 : 0); } cout << ans << '\n'; } int main() { ios::sync_with_stdio(!cin.tie(0)); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { cin >> b[i]; } if (*max_element(b + 1, b + n + 1) == *min_element(b + 1, b + n + 1)) { solve2(); return 0; } bool sub3 = true; for (int i = 2; i <= n; i++) { if (a[i] <= a[i - 1]) { sub3 = false; } } if (sub3) { map<int, int> mp; for (int i = 1; i <= n; i++) { mp[a[i]] = i; } for (int i = 1; i <= n; i++) { b[i] = mp[b[i]]; } vector<int> dp(n + 1); for (int i = 1; i <= n; i++) { dp[i] = 1; for (int j = 1; j < i; j++) { if (b[j] > 0 && b[i] >= b[j]) { dp[i] = max(dp[i], dp[j] + 1); } } } cout << *max_element(dp.begin(), dp.end()) << '\n'; return 0; } if (n <= 10) { auto c = a; int ans = 0; function<void(int*)> Brut = [&](int* niz) { int cnt = 0; for (int i = 1; i <= n; i++) { cnt += niz[i] == b[i]; } ans = max(ans, cnt); for (int i = 1; i <= n; i++) { int mx = 0; int novi[n + 1]; for (int j = 1; j <= n; j++) { novi[j] = niz[j]; } for (int j = i; j <= n; j++) { mx = max(mx, niz[j]); bool ok = false; for (int l = i; l <= j; l++) { if (niz[l] != mx) { ok = true; } novi[l] = mx; } if (ok) { Brut(novi); } } } }; Brut(c); cout << ans << '\n'; } }
#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...