#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define F first
#define S second
#define pb push_back
#define ld long double
#define int ll
#define pll pair <ll,ll>
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define TIME 1.0*clock()/CLOCKS_PER_SEC
using namespace std;
using namespace __gnu_pbds;
mt19937_64 gen(time(0));
int n,q;
vector <int> a;
vector <int> b;
void init() {
cin>>n;
a.resize(n);
for (int i = 0;i < n;i++)
cin>>a[i];
b.resize(n);
for (int i = 0;i < n;i++)
cin>>b[i];
}
ll ans = 0;
void output() {
cout<<ans<<'\n';
}
void solve() {
bool can = true;
int pos = -1;
int kol = 0;
for (int i = 0;i < n;i++)
{
if (a[i] > b[i]) {
if (can != true) ans+=kol;
can = true;
kol = 0;
}
else if (a[i] == b[i]) {++kol;can = false;}
else ++kol;
}
if (can != true) ans+=kol;
}
int dp[(int)(202)][(int)(404)];
void solve2() {
map <int,int> mp;
int kol = 0;
vector <int> c;
for (int i = 0;i < n;i++)
c.pb(a[i]);
for (int i = 0;i < n;i++)
c.pb(b[i]);
sort(c.begin(),c.end());
for (int i = 0;i < n;i++)
{
a[i] = lower_bound(c.begin(),c.end(),a[i])-c.begin();
}
for (int i = 0;i < n;i++)
{
b[i] = lower_bound(c.begin(),c.end(),b[i])-c.begin();
}
for (int i = 0;i < n;i++)
{
for (int j = i;j < n;j++)
{
int oz = 0;
for (int q = 0;q < 404;q++)
oz = max(oz,dp[j][q]);
int kol = 0;
for (int q = j;q < n;q++)
{
if (a[q] > a[i]) continue;
if (b[q] == a[i]) ++kol;
dp[q + 1][a[i]] = max(dp[q + 1][a[i]],oz + kol);
}
}
}
for (int i = 0;i < 404;i++)
ans = max(ans,dp[n][i]);
}
int32_t main() {
srand(time(0));
//freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
IOS;
int test;
test = 1;
while (test--) {
init();
bool has = true;
for (int i = 0;i < n - 1;i++)
if (b[i] != b[i + 1]) {
has = false;
break;
}
if (has == true) solve();
else solve2();
output();
}
exit(0);}
/*3 5 7 9 10 11*/
/*5 14 13 8 14 11*/
Compilation message
exam.cpp: In function 'void solve()':
exam.cpp:34:9: warning: unused variable 'pos' [-Wunused-variable]
34 | int pos = -1;
| ^~~
exam.cpp: In function 'void solve2()':
exam.cpp:51:9: warning: unused variable 'kol' [-Wunused-variable]
51 | int kol = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
5 ms |
620 KB |
Output is correct |
3 |
Correct |
17 ms |
1772 KB |
Output is correct |
4 |
Correct |
16 ms |
2048 KB |
Output is correct |
5 |
Correct |
26 ms |
1900 KB |
Output is correct |
6 |
Correct |
14 ms |
1900 KB |
Output is correct |
7 |
Correct |
15 ms |
1900 KB |
Output is correct |
8 |
Correct |
24 ms |
1900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
2412 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |