제출 #390377

#제출 시각아이디문제언어결과실행 시간메모리
390377MilosMilutinovicExam (eJOI20_exam)C++14
12 / 100
31 ms1496 KiB
/** * author: milos * created: 16.04.2021 02:05:22 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); 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]; } bool same = true; for (int i = 0; i < n; i++) { if (b[i] != b[0]) { same = false; } } if (same) { vector<int> pos; for (int i = 0; i < n; i++) { if (a[i] == b[i]) { pos.push_back(i); } } for (int i : pos) { for (int j = i + 1; j < n; j++) { if (a[j] >= b[j]) { break; } a[j] = a[i]; } for (int j = i - 1; j >= 0; j--) { if (a[j] >= b[j]) { break; } a[j] = a[i]; } } int cnt = 0; for (int i = 0; i < n; i++) { if (a[i] == b[i]) { cnt++; } } cout << cnt << '\n'; return 0; } vector<int> dp(n); for (int i = 0; i < n; i++) { bool add = (a[i] == b[i]); map<int, int> cnt; int bonus = 0; bool ok = true; for (int j = i - 1; j >= 0; j--) { dp[i] = max(dp[i], dp[j]); if (a[i] <= a[j]) { ok = false; } if (ok && b[j] == a[i]) { bonus++; } dp[i] = max(dp[i], (j > 0 ? dp[j - 1] : 0) + bonus); } if (i > 0) { dp[i] = max(dp[i], dp[i - 1]); } if (add) { dp[i] += 1; } } cout << dp[n - 1] << '\n'; 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...