Submission #1070413

#TimeUsernameProblemLanguageResultExecution timeMemory
1070413juicyExam (eJOI20_exam)C++17
12 / 100
15 ms3160 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n), b(n); for (int &x : a) { cin >> x; } for (int &x : b) { cin >> x; } if (n > 5000) { int res = 0; for (int i = 0; i < n; ++i) { if (a[i] > b[0]) { continue; } int j = i - 1; bool flg = 0; while (j + 1 < n && a[j + 1] <= b[0]) { flg |= a[++j] == b[0]; } res += flg * (j - i + 1); i = j; } cout << res; exit(0); } vector<int> comp; for (int i = 0; i < n; ++i) { comp.push_back(a[i]); comp.push_back(b[i]); } sort(comp.begin(), comp.end()); comp.erase(unique(comp.begin(), comp.end()), comp.end()); for (int i = 0; i < n; ++i) { a[i] = lower_bound(comp.begin(), comp.end(), a[i]) - comp.begin(); b[i] = lower_bound(comp.begin(), comp.end(), b[i]) - comp.begin(); } int m = comp.size(); vector<int> dp(n + 1), cnt(m); dp[0] = 0; for (int i = 1; i <= n; ++i) { dp[i] = dp[i - 1]; int ma = 0; for (int j = i - 1; j >= 0; --j) { ma = max(ma, a[j]); ++cnt[b[j]]; dp[i] = max(dp[i], dp[j] + cnt[ma]); } for (int j = 0; j < i; ++j) { cnt[b[j]] = 0; } } cout << dp.back(); 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...