# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
469032 |
2021-08-30T12:51:50 Z |
kderylo |
Exam (eJOI20_exam) |
C++17 |
|
188 ms |
165596 KB |
#include <iostream>
#include <vector>
using namespace std;
const int stala=1e5+10;
const int stala2=5010;
int tab[stala];
int tab2[stala];
int przedzialy[stala][2];
int dp[stala2][stala2];
int pref[stala2][stala2];
vector<int>wektor;
vector<int>wektor2;
void wyznacz_przedzial(int ile)
{
for(int i=1;i<=ile;i++)
{
while(!wektor.empty()&&wektor.back()<=tab[i])
{
przedzialy[wektor2.back()][1]=i-1;
wektor.pop_back();
wektor2.pop_back();
}
wektor.push_back(tab[i]);
wektor2.push_back(i);
}
while(!wektor.empty())
{
przedzialy[wektor2.back()][1]=ile;
wektor.pop_back();
wektor2.pop_back();
}
for(int i=ile;i>=1;i--)
{
while(!wektor.empty()&&wektor.back()<=tab[i])
{
przedzialy[wektor2.back()][0]=i+1;
wektor.pop_back();
wektor2.pop_back();
}
wektor.push_back(tab[i]);
wektor2.push_back(i);
}
while(!wektor.empty())
{
przedzialy[wektor2.back()][0]=1;
wektor.pop_back();
wektor2.pop_back();
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ile;
cin>>ile;
for(int i=1;i<=ile;i++)
{
cin>>tab[i];
}
for(int i=1;i<=ile;i++)
{
cin>>tab2[i];
}
wyznacz_przedzial(ile);
if(ile<=5000)
{
for(int i=1;i<=ile;i++)
{
for(int j=1;j<=ile;j++)
{
if(przedzialy[j][0]<=i&&i<=przedzialy[j][1])
{
dp[i][j]=max(dp[i-1][j],pref[i-1][j-1]);
if(tab[j]==tab2[i])
{
dp[i][j]++;
}
}
pref[i][j]=max(pref[i][j-1],dp[i][j]);
}
}
int res=0;
for(int i=1;i<=ile;i++)
{
res=max(res,dp[ile][i]);
}
cout<<res;
}
else
{
int takie_same=tab2[1];
bool xyz=true;
for(int i=2;i<=ile;i++)
{
if(tab2[i]!=takie_same)
{
xyz=false;
break;
}
}
if(xyz==true)
{
int res=0;
for(int i=1;i<=ile;i++)
{
if(tab[i]==takie_same)
{
res+=przedzialy[i][1]-przedzialy[i][0]+1;
}
}
cout<<res;
}
else
{
cout<<"0";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12876 KB |
Output is correct |
2 |
Incorrect |
6 ms |
720 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
5 ms |
5836 KB |
Output is correct |
3 |
Correct |
37 ms |
39920 KB |
Output is correct |
4 |
Correct |
174 ms |
157636 KB |
Output is correct |
5 |
Correct |
172 ms |
165544 KB |
Output is correct |
6 |
Correct |
176 ms |
165592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
588 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
2 ms |
2124 KB |
Output is correct |
11 |
Correct |
2 ms |
2124 KB |
Output is correct |
12 |
Correct |
2 ms |
2124 KB |
Output is correct |
13 |
Correct |
2 ms |
2124 KB |
Output is correct |
14 |
Correct |
2 ms |
2124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
5 ms |
5836 KB |
Output is correct |
9 |
Correct |
37 ms |
39920 KB |
Output is correct |
10 |
Correct |
174 ms |
157636 KB |
Output is correct |
11 |
Correct |
172 ms |
165544 KB |
Output is correct |
12 |
Correct |
176 ms |
165592 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
1100 KB |
Output is correct |
16 |
Correct |
2 ms |
2124 KB |
Output is correct |
17 |
Correct |
2 ms |
2124 KB |
Output is correct |
18 |
Correct |
2 ms |
2124 KB |
Output is correct |
19 |
Correct |
2 ms |
2124 KB |
Output is correct |
20 |
Correct |
2 ms |
2124 KB |
Output is correct |
21 |
Correct |
2 ms |
2112 KB |
Output is correct |
22 |
Correct |
15 ms |
14660 KB |
Output is correct |
23 |
Correct |
164 ms |
118692 KB |
Output is correct |
24 |
Correct |
170 ms |
118792 KB |
Output is correct |
25 |
Correct |
162 ms |
119420 KB |
Output is correct |
26 |
Correct |
166 ms |
125960 KB |
Output is correct |
27 |
Correct |
175 ms |
136760 KB |
Output is correct |
28 |
Correct |
176 ms |
153660 KB |
Output is correct |
29 |
Correct |
180 ms |
165556 KB |
Output is correct |
30 |
Correct |
188 ms |
165548 KB |
Output is correct |
31 |
Correct |
183 ms |
165596 KB |
Output is correct |
32 |
Correct |
170 ms |
143184 KB |
Output is correct |