제출 #433032

#제출 시각아이디문제언어결과실행 시간메모리
433032Valaki2Exam (eJOI20_exam)C++14
12 / 100
29 ms1492 KiB
#include <bits/stdc++.h> using namespace std; int n; vector<int> a; vector<int> b; void solve_bf() { } void solve_bequal() { int x = b[1]; int last = 0; bool ok = false; int ans = 0; a.push_back(x + 1); for(int i = 1; i <= (n + 1); ++i) { if(a[i] > x) { if(ok) { ans += i - last - 1; ok = false; } last = i; } else if(a[i] == x) { ok = true; } } cout << ans << "\n"; } void solve_astrictlyincreasing() { vector<int> dp(1 + n, 0); vector<bool> ok(1 + n, false); for(int i = 1; i <= n; ++i) { dp[i] = dp[i - 1]; if(a[i] == b[i]) { ++dp[i]; ok[i] = true; } int cur = dp[i]; int l = i; for(int j = i - 1; j >= 1; --j) { if(ok[j]) --cur; if(a[i] == b[j]) ++cur; if(cur > dp[i]) { dp[i] = cur; l = j; } } for(int j = i - 1; j >= l; --j) { if(a[i] == b[j]) ok[j] = true; else ok[j] = false; } } cout << dp[n] << "\n"; } void solve() { cin >> n; a.assign(1 + n, 0); b.assign(1 + n, 0); for(int i = 1; i <= n; ++i) cin >> a[i]; for(int i = 1; i <= n; ++i) cin >> b[i]; set<int> b_set; for(int i = 1; i <= n; ++i) { b_set.insert(b[i]); } /*if(n <= 10) { solve_bf(); } else */if(b_set.size() == 1) { solve_bequal(); } else { solve_astrictlyincreasing(); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); 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...