# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
463391 |
2021-08-11T05:34:23 Z |
tengiz05 |
Exam (eJOI20_exam) |
C++17 |
|
55 ms |
8324 KB |
#include <bits/stdc++.h>
using i64 = long long;
constexpr int N = 5005;
int par[N][2 * N];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
for (int i = 0; i < n; i++) {
std::cin >> b[i];
}
auto c = a;
c.insert(c.end(), b.begin(), b.end());
std::sort(c.begin(), c.end());
c.erase(std::unique(c.begin(), c.end()), c.end());
for (int i = 0; i < n; i++) {
a[i] = std::lower_bound(c.begin(), c.end(), a[i]) - c.begin();
b[i] = std::lower_bound(c.begin(), c.end(), b[i]) - c.begin();
}
if (n <= 5000) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
par[i + 1][j] = par[i][j] + (b[i] == j);
}
}
std::vector<int> pref(n + 1), suf(n + 1);
for (int i = 0; i < n; i++) {
pref[i + 1] = pref[i] + (a[i] == b[i]);
}
std::vector<int> dp(n + 1);
for (int i = 1; i <= n; i++) {
dp[i] = dp[i - 1] + (a[i - 1] == b[i - 1]);
for (int j = i, mx = 0; j >= 1; j--) {
mx = std::max(mx, a[j - 1]);
dp[i] = std::max(dp[i], dp[j - 1] + par[i][mx] - par[j - 1][mx]);
}
}
std::cout << dp[n] << "\n";
} else {
if (std::count(b.begin(), b.end(), b[0]) == n) {
std::vector<int> t(n, 0);
for (int i = 0; i < n; i++) {
if (a[i] == b[0]) {
int j = i;
while (j >= 0 && a[j] <= b[0] && !t[j]) {
t[j--] = 1;
}
j = i + 1;
while (j < n && a[j] <= b[0] && !t[j]) {
t[j++] = 1;
}
}
}
std::cout << std::accumulate(t.begin(), t.end(), 0) << "\n";
} else {
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
8324 KB |
Output is correct |
2 |
Correct |
7 ms |
716 KB |
Output is correct |
3 |
Correct |
31 ms |
2020 KB |
Output is correct |
4 |
Correct |
21 ms |
2272 KB |
Output is correct |
5 |
Correct |
55 ms |
2272 KB |
Output is correct |
6 |
Correct |
22 ms |
2284 KB |
Output is correct |
7 |
Correct |
26 ms |
2264 KB |
Output is correct |
8 |
Correct |
53 ms |
2252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
352 KB |
Output is correct |
5 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |