Submission #791371

#TimeUsernameProblemLanguageResultExecution timeMemory
791371otariusExam (eJOI20_exam)C++17
0 / 100
21 ms39488 KiB
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <cstring> #include <queue> #include <map> #include <cmath> #include <iomanip> using namespace std; #define ff first #define sc second #define pb push_back #define ll long long #define pll pair<ll, ll> #define pii pair <int, int> #define ull unsigned long long // #define int long long // #define int unsigned long long const ll inf = 1e9 + 7; const ll weirdMod = 998244353; map<int, int> mp; int rnk = 0; int pref[5001][10000], dp[5001]; void solve() { int n; cin >> n; if (n > 5000) { int a[n + 1], b[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; bool f = 0; for (int i = 1; i <= n; i++) { if (a[i] == b[i]) { f = 1; break; } } cout << (f ? n : 0); return; } set<int> st; int a[n + 1], b[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; st.insert(a[i]); } for (int i = 1; i <= n; i++) { cin >> b[i]; st.insert(b[i]); } for (int v : st) mp[v] = rnk++; for (int i = 1; i <= n; i++) { a[i] = mp[a[i]]; b[i] = mp[b[i]]; for (int j = 0; j < 10000; j++) { pref[i][j] = pref[i - 1][j]; } pref[i][b[i]]++; } for (int j = 1; j <= n; j++) { int mx = 0; for (int i = j; i >= 1; i--) { mx = max(mx, a[i]); dp[j] = max(dp[j], dp[i - 1] + pref[j][mx] - pref[i - 1][mx]); } } int mx = 0; for (int i = 1; i <= n; i++) mx = max(mx, dp[i]); cout << mx; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); cout << '\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...