# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
820230 |
2023-08-11T01:50:45 Z |
Zanite |
Exam (eJOI20_exam) |
C++17 |
|
444 ms |
295368 KB |
#include <bits/stdc++.h>
using namespace std;
const int iINF = 1e9;
const int maxN = 5023;
const int maxNN = 100'023;
int N, M, A[maxNN], B[maxNN];
vector<int> compress;
namespace Subtask2 {
void solve() {
int qb = B[1];
int ans = 0, run = 0;
bool hasB = false;
for (int i = 1; i <= N; i++) {
if (A[i] > qb) {
run = 0;
hasB = false;
continue;
}
run++;
if (A[i] == qb) {hasB = true;}
if (hasB) {
ans += run;
run = 0;
}
}
cout << ans << '\n';
}
}
namespace Subtask4 {
void solve() {
exit(-1);
}
}
namespace Subtask6 {
int dp[maxN][maxN], mx[maxN][maxN], pf[maxN][maxN];
void solve() {
for (int l = 1; l <= N; l++) {
mx[l][l] = A[l];
for (int r = l+1; r <= N; r++) {
mx[l][r] = max(mx[l][r-1], A[r]);
mx[r][l] = mx[l][r];
}
}
for (int i = 1; i <= N; i++) {
for (int val = 1; val <= N; val++) {
pf[i][val] = -iINF;
}
}
pf[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int val = 1; val <= N; val++) {
if (mx[val][i] == A[val]) {
dp[i][val] = pf[i-1][val] + (B[i] == A[val]);
// cout << "dp[" << i << "][" << val << "] = " << dp[i][val] << '\n';
} else {
dp[i][val] = -iINF;
}
pf[i][val] = max(pf[i][val-1], dp[i][val]);
}
}
int ans = pf[N][N];
cout << ans << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> A[i];
compress.push_back(A[i]);
}
for (int i = 1; i <= N; i++) {
cin >> B[i];
compress.push_back(B[i]);
}
sort(compress.begin(), compress.end());
compress.erase(unique(compress.begin(), compress.end()), compress.end());
M = compress.size();
for (int i = 1; i <= N; i++) {
A[i] = lower_bound(compress.begin(), compress.end(), A[i]) - compress.begin() + 1;
B[i] = lower_bound(compress.begin(), compress.end(), B[i]) - compress.begin() + 1;
}
bool allEqualB = true;
for (int i = 2; i <= N; i++) {
if (B[i] != B[1]) allEqualB = false;
}
const int sub6Limit = 5000;
if (allEqualB) {
Subtask2::solve();
} else if (sub6Limit) {
Subtask6::solve();
} else {
Subtask4::solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
980 KB |
Output is correct |
3 |
Correct |
22 ms |
2984 KB |
Output is correct |
4 |
Correct |
12 ms |
2380 KB |
Output is correct |
5 |
Correct |
37 ms |
4036 KB |
Output is correct |
6 |
Correct |
14 ms |
2392 KB |
Output is correct |
7 |
Correct |
18 ms |
2516 KB |
Output is correct |
8 |
Correct |
37 ms |
3952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
5 ms |
9300 KB |
Output is correct |
3 |
Correct |
55 ms |
71348 KB |
Output is correct |
4 |
Correct |
365 ms |
283472 KB |
Output is correct |
5 |
Correct |
389 ms |
295356 KB |
Output is correct |
6 |
Correct |
421 ms |
295340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
444 ms |
295328 KB |
Output is correct |
2 |
Runtime error |
131 ms |
85100 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
1620 KB |
Output is correct |
10 |
Correct |
1 ms |
3156 KB |
Output is correct |
11 |
Correct |
1 ms |
3156 KB |
Output is correct |
12 |
Correct |
2 ms |
3156 KB |
Output is correct |
13 |
Correct |
2 ms |
3156 KB |
Output is correct |
14 |
Correct |
1 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
9300 KB |
Output is correct |
9 |
Correct |
55 ms |
71348 KB |
Output is correct |
10 |
Correct |
365 ms |
283472 KB |
Output is correct |
11 |
Correct |
389 ms |
295356 KB |
Output is correct |
12 |
Correct |
421 ms |
295340 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
1620 KB |
Output is correct |
16 |
Correct |
1 ms |
3156 KB |
Output is correct |
17 |
Correct |
1 ms |
3156 KB |
Output is correct |
18 |
Correct |
2 ms |
3156 KB |
Output is correct |
19 |
Correct |
2 ms |
3156 KB |
Output is correct |
20 |
Correct |
1 ms |
3156 KB |
Output is correct |
21 |
Correct |
2 ms |
3156 KB |
Output is correct |
22 |
Correct |
14 ms |
24148 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
382 ms |
295360 KB |
Output is correct |
25 |
Correct |
391 ms |
295368 KB |
Output is correct |
26 |
Correct |
383 ms |
295324 KB |
Output is correct |
27 |
Correct |
386 ms |
295260 KB |
Output is correct |
28 |
Correct |
395 ms |
295300 KB |
Output is correct |
29 |
Correct |
415 ms |
295252 KB |
Output is correct |
30 |
Correct |
396 ms |
295352 KB |
Output is correct |
31 |
Correct |
396 ms |
295304 KB |
Output is correct |
32 |
Correct |
392 ms |
295352 KB |
Output is correct |