# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
799676 |
2023-07-31T19:30:10 Z |
josiftepe |
Exam (eJOI20_exam) |
C++14 |
|
187 ms |
99472 KB |
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int n;
int a[maxn], b[maxn];
int L[maxn], R[maxn];
void solve_subtask2() {
int x = b[0];
int res = 0;
for(int i = 0; i < n; i++) {
if(a[i] == x) {
res++;
int j = i - 1;
while(j >= 0 and a[j] <= x) {
j--;
res++;
}
j = i + 1;
while(j < n and a[j] <= x) {
res++;
j++;
}
i = j - 1;
}
}
cout << res << endl;
}
int dp[5005][5005];
int rec(int i, int j) {
if(i < 0 or j < 0) {
return 0;
}
if(dp[i][j] != -1) {
return dp[i][j];
}
int res = 0;
if(a[i] == b[j] and L[i] < j and R[i] > j) {
res = max(res, rec(i, j - 1) + 1);
}
res = max(res, rec(i - 1, j));
res = max(res, rec(i, j - 1));
return dp[i][j] = res;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
set<int> st;
for(int i = 0; i < n; i++) {
cin >> a[i];
}
for(int i = 0; i < n; i++) {
cin >> b[i];
st.insert(b[i]);
}
if((int) st.size() == 1) {
solve_subtask2();
return 0;
}
else if(n <= 5005){
for(int i = 0; i < n; i++) {
int idx1 = -1;
for(int j = 0; j < i; j++) {
if(a[i] < b[j]) {
idx1 = j;
}
}
int idx2 = n;
for(int j = i + 1; j < n; j++) {
if(a[i] < b[j]) {
idx2 = j;
break;
}
}
L[i] = idx1;
R[i] = idx2;
}
memset(dp, -1, sizeof dp);
cout << rec(n - 1, n - 1) << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
98252 KB |
Output is correct |
2 |
Correct |
32 ms |
98388 KB |
Output is correct |
3 |
Correct |
32 ms |
98256 KB |
Output is correct |
4 |
Correct |
33 ms |
98360 KB |
Output is correct |
5 |
Correct |
39 ms |
98336 KB |
Output is correct |
6 |
Correct |
34 ms |
98304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
872 KB |
Output is correct |
3 |
Correct |
13 ms |
2076 KB |
Output is correct |
4 |
Correct |
9 ms |
1404 KB |
Output is correct |
5 |
Correct |
18 ms |
2692 KB |
Output is correct |
6 |
Correct |
9 ms |
1392 KB |
Output is correct |
7 |
Correct |
11 ms |
1612 KB |
Output is correct |
8 |
Correct |
18 ms |
2684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
98388 KB |
Output is correct |
2 |
Incorrect |
35 ms |
98516 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
187 ms |
99472 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
98252 KB |
Output is correct |
2 |
Correct |
32 ms |
98388 KB |
Output is correct |
3 |
Correct |
32 ms |
98256 KB |
Output is correct |
4 |
Correct |
33 ms |
98360 KB |
Output is correct |
5 |
Correct |
39 ms |
98336 KB |
Output is correct |
6 |
Correct |
34 ms |
98304 KB |
Output is correct |
7 |
Incorrect |
31 ms |
98388 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
98252 KB |
Output is correct |
2 |
Correct |
32 ms |
98388 KB |
Output is correct |
3 |
Correct |
32 ms |
98256 KB |
Output is correct |
4 |
Correct |
33 ms |
98360 KB |
Output is correct |
5 |
Correct |
39 ms |
98336 KB |
Output is correct |
6 |
Correct |
34 ms |
98304 KB |
Output is correct |
7 |
Correct |
32 ms |
98388 KB |
Output is correct |
8 |
Incorrect |
35 ms |
98516 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |