Submission #425593

#TimeUsernameProblemLanguageResultExecution timeMemory
425593MilosMilutinovicExam (eJOI20_exam)C++14
12 / 100
1083 ms3020 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; } 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...