# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
464274 |
2021-08-12T16:29:56 Z |
gesgha |
Exam (eJOI20_exam) |
C++17 |
|
1000 ms |
1692 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fr(x, l, r) for(int x = l; x <= r; x++)
#define rf(x, l, r) for(int x = l; x >= r; x--)
#define fe(x, y) for(auto& x : y)
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define pw(x) (ull(1) << ull(x))
#define all(x) (x).begin(),x.end()
#define sz(x) (int)x.size()
#define mt make_tuple
#define ve vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;
typedef pair <ld,ld> pld;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key
template<typename T>
bool umn(T& a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T>
bool umx(T& a, T b) { return a < b ? a = b, 1 : 0; }
const ll inf = 1e18;
const int intf = 1e9;
const ll mod = 1e9 + 7;
const ld eps = 0.00000001;
const ll N = 1e5 + 5;
int a[N], b[N], B, f[N], n, dp[N], ans;
queue <ll> q;
void add(int pos, int& ans){
if(pos < 0 || pos >= n || f[pos] || a[pos] > B)return;
ans++;
f[pos] = 1;
q.push(pos);
}
void rec(){
int cnt = 0;
fr(i, 0, n - 1){
cnt += bool(a[i] == b[i]);
}
ans = max(ans, cnt);
fr(i, 0, n - 1){
int c = a[i];
if(i < n - 1 && umx(a[i], a[i + 1])){
rec();
a[i] = c;
}
if(i && umx(a[i], a[i - 1])){
rec();
a[i] = c;
}
}
}
int main(){
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt","w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
#else
// freopen("mountains.in", "r", stdin);
// freopen("mountains.out","w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
cin >> n;
fr(i, 0, n - 1){
cin >> a[i];
}
bool ff = 0;
fr(i, 0, n - 1){
cin >> b[i];
if(i && b[i] != b[i - 1]){
ff = 1;
}
}
if(!ff){
int ans = 0;
B = b[0];
fr(i, 0, n - 1){
if(a[i] == B){
q.push(i);
f[i] = 1;
ans++;
}
}
while(!q.empty()){
int p = q.front();
add(p + 1, ans);
add(p - 1, ans);
q.pop();
}
cout << ans << endl;
}
else{
rec();
cout << ans << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
36 ms |
204 KB |
Output is correct |
6 |
Execution timed out |
1090 ms |
204 KB |
Time limit exceeded |
# |
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 |
19 ms |
1124 KB |
Output is correct |
4 |
Correct |
16 ms |
1484 KB |
Output is correct |
5 |
Correct |
32 ms |
1460 KB |
Output is correct |
6 |
Correct |
16 ms |
1692 KB |
Output is correct |
7 |
Correct |
18 ms |
1460 KB |
Output is correct |
8 |
Correct |
24 ms |
1092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1094 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
580 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
36 ms |
204 KB |
Output is correct |
6 |
Execution timed out |
1090 ms |
204 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
36 ms |
204 KB |
Output is correct |
6 |
Execution timed out |
1090 ms |
204 KB |
Time limit exceeded |