# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
833354 |
2023-08-22T04:52:31 Z |
vjudge1 |
Exam (eJOI20_exam) |
C++17 |
|
58 ms |
1560 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
const int N = 1e5+10;
int n,ans;
int temp1,temp2;
int memo[N];
int h[N],t[N];
bool vis[N];
void sub2() {
for(int i=1; i<=n; i++) {
if(h[i] == t[1]) {
for(int j=i-1; j>=1; j--) {
if(vis[j]) break;
if(h[j] < h[i]) {
h[j] = h[i];
vis[j] = true;
}
else break;
}
for(int j=i+1; j<=n; j++) {
if(vis[j]) break;
if(h[j] < h[i]) {
h[j] = h[i];
vis[j] = true;
}
else break;
}
}
}
for(int i=1; i<=n; i++) if(h[i] == t[i]) ans++;
cout << ans << endl;
}
int dp(int idx) {
if(idx == 0) return 0;
if(memo[idx] == -1) {
int var = 0;
memo[idx] = 0;
for(int i=idx; i>=1; i--) {
if(h[idx] == t[i]) var++;
memo[idx] = max(memo[idx],dp(i-1)+var);
}
}
return memo[idx];
}
int main() {
memset(memo,-1,sizeof(memo));
cin >> n;
// n = 5000;
// for(int i=1; i<=n; i++) h[i] = i;
// for(int i=1; i<=n; i++) t[i] = i;
// temp1 = n-1;
for(int i=1; i<=n; i++) {
cin >> h[i];
if(i > 1 && h[i] > h[i-1]) temp1++;
}
for(int i=1; i<=n; i++) {
cin >> t[i];
if(i > 1 && t[i] == t[i-1]) temp2++;
}
if(temp2 == n-1) {
sub2();
return 0;
}
if(temp1 == n-1) {
cout << dp(n) << endl;
}
// if(n <= 10) {
// for(int i=1; i<=n; i++) {
// bool b = true;
// ll temp = 0;
// for(int j=1; j<=i-1; j++) {
// if(a[i] < a[j]) {
// b = false;
// break;
// }
// else if(h[i] == t[i]) {
// temp++;
// }
// }
// if(b) {
// ans = max(ans,dp(i) + temp);
// }
// }
// }
}
/*
3
1 2 4
2 2 3
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
13 ms |
852 KB |
Output is correct |
3 |
Correct |
36 ms |
1356 KB |
Output is correct |
4 |
Correct |
22 ms |
1468 KB |
Output is correct |
5 |
Correct |
58 ms |
1484 KB |
Output is correct |
6 |
Correct |
31 ms |
1404 KB |
Output is correct |
7 |
Correct |
26 ms |
1560 KB |
Output is correct |
8 |
Correct |
56 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |