# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
464307 |
2021-08-12T20:30:33 Z |
AdamGS |
Exam (eJOI20_exam) |
C++14 |
|
695 ms |
400256 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e5+7;
int a[LIM], b[LIM], dp[5007][5007], ma[5007][5007], n;
void subtask2() {
rep(i, n-1) if(a[i+1]==b[1] && a[i+1]>=a[i+2]) a[i+2]=a[i+1];
for(int i=n-1; i; --i) if(a[i+1]==b[1] && a[i+1]>=a[i]) a[i]=a[i+1];
int ans=0;
rep(i, n) if(a[i+1]==b[i+1]) ++ans;
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
rep(i, n) cin >> a[i+1];
rep(i, n) cin >> b[i+1];
bool ok2=true;
rep(i, n-1) if(b[i+1]!=b[i+2]) ok2=false;
if(ok2) {
subtask2();
return 0;
}
rep(i, n) {
for(int j=i; j<n; ++j) {
ma[i+1][j+1]=max(ma[i+1][j], a[j+1]);
}
}
rep(i, n) rep(j, n) {
dp[i+1][j+1]=max(dp[i+1][j], dp[i][j+1]);
if(a[i+1]==b[j+1] && ma[min(i+1, j+1)][max(i+1, j+1)]==a[i+1]) {
dp[i+1][j+1]=max(dp[i+1][j+1], dp[i+1][j]+1);
}
}
cout << dp[n][n] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
588 KB |
Output is correct |
3 |
Correct |
18 ms |
1528 KB |
Output is correct |
4 |
Correct |
16 ms |
1432 KB |
Output is correct |
5 |
Correct |
31 ms |
1480 KB |
Output is correct |
6 |
Correct |
16 ms |
1484 KB |
Output is correct |
7 |
Correct |
16 ms |
1548 KB |
Output is correct |
8 |
Correct |
25 ms |
1564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
5836 KB |
Output is correct |
3 |
Correct |
36 ms |
39872 KB |
Output is correct |
4 |
Correct |
165 ms |
157488 KB |
Output is correct |
5 |
Correct |
183 ms |
165396 KB |
Output is correct |
6 |
Correct |
176 ms |
165316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
165296 KB |
Output is correct |
2 |
Runtime error |
695 ms |
400256 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 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 |
1088 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 |
2200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
5 ms |
5836 KB |
Output is correct |
9 |
Correct |
36 ms |
39872 KB |
Output is correct |
10 |
Correct |
165 ms |
157488 KB |
Output is correct |
11 |
Correct |
183 ms |
165396 KB |
Output is correct |
12 |
Correct |
176 ms |
165316 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 |
1088 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 |
2200 KB |
Output is correct |
21 |
Correct |
2 ms |
2124 KB |
Output is correct |
22 |
Correct |
13 ms |
14228 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
248 ms |
165412 KB |
Output is correct |
25 |
Correct |
211 ms |
165412 KB |
Output is correct |
26 |
Correct |
191 ms |
165356 KB |
Output is correct |
27 |
Correct |
201 ms |
165284 KB |
Output is correct |
28 |
Correct |
181 ms |
165372 KB |
Output is correct |
29 |
Correct |
185 ms |
165352 KB |
Output is correct |
30 |
Correct |
182 ms |
165356 KB |
Output is correct |
31 |
Correct |
183 ms |
165380 KB |
Output is correct |
32 |
Correct |
182 ms |
165440 KB |
Output is correct |