# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
783143 |
2023-07-14T15:57:57 Z |
pera |
Exam (eJOI20_exam) |
C++17 |
|
17 ms |
3924 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 1;
main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int n , oK = 1;cin >> n;
vector<int> a(n + 1) , b(n + 1);
for(int i = 1;i <= n;i ++){
cin >> a[i];
}
for(int i = 1;i <= n;i ++){
cin >> b[i];
if(i != 1) oK &= (b[i] == b[i - 1]);
}
if(oK){
int c = 0;
for(int i = 1;i <= n;i ++){
int cc = 0 , k = 0;
while(a[i] <= b[i] && i <= n){
if(a[i] == b[i]) k = 1;
++ cc , ++ i;
}
if(k) c += cc;
}
cout << c << endl;
}else{
oK = 1;
for(int i = 2;i <= n;i ++){
oK &= (a[i] > a[i - 1]);
}
if(oK){
vector<int> dp(n + 1);
vector<vector<int>> c(n + 1 , vector<int>(n + 1));
for(int i = 1;i <= n;i ++){
for(int j = 1;j <= n;j ++){
c[i][j] = c[i][j - 1] + (b[j] == a[i]);
}
}
dp[1] = (a[1] == b[1]);
for(int i = 2;i <= n;i ++){
for(int j = 1;j < i;j ++){
dp[i] = max(dp[i] , dp[j] + c[i][i] - c[i][j - 1]);
}
}
cout << dp[n] << endl;
}
}
}
Compilation message
exam.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
260 KB |
Output is correct |
2 |
Correct |
4 ms |
652 KB |
Output is correct |
3 |
Correct |
13 ms |
2760 KB |
Output is correct |
4 |
Correct |
9 ms |
2268 KB |
Output is correct |
5 |
Correct |
16 ms |
3924 KB |
Output is correct |
6 |
Correct |
9 ms |
2276 KB |
Output is correct |
7 |
Correct |
10 ms |
2444 KB |
Output is correct |
8 |
Correct |
17 ms |
3804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |