#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100, K = 20;
bool case2 = 1;
int k, dp[N][2], n;
vector<int> A;
void init(int NN, std::vector<int> a){
n = NN;
if(n > 2000) case2 = 0;
k = max_element(a.begin(), a.end()) - a.begin();
A = a;
}
int max_towers(int L, int R, int D){
if(!case2){
if(R <= k || L >= k) return 1;
if(A[L] <= A[k] - D && A[R] <= A[k] - D) return 2;
return 1;
}
for(int i = 0; i < n; ++i) dp[i][0] = 1, dp[i][1] = 0;
vector<int> left(n, -1), right(n, -1);
deque<pair<int, int>> q;
for(int i = L; i <= R; ++i){
while(!q.empty() && q.front().first < A[i] + D){
q.pop_front();
}
if(!q.empty()) left[i] = q.front().second;
q.push_front({A[i], i});
}
q.clear();
for(int i = R; i >= L; --i){
while(!q.empty() && q.front().first < A[i] + D){
q.pop_front();
}
if(!q.empty()) right[i] = q.front().second;
q.push_front({A[i], i});
}
for(int i = L; i <= R; ++i){
if(left[i] != -1) dp[i][0] = dp[left[i]][1] + 1;
if(right[i] != -1) dp[right[i]][1] = max(dp[right[i]][1], dp[i][0]);
}
int ans = 0;
for(int i = L; i <= R; ++i) ans=max(ans,dp[i][0]);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
456 ms |
936 KB |
Output is correct |
2 |
Correct |
674 ms |
1468 KB |
Output is correct |
3 |
Correct |
787 ms |
1452 KB |
Output is correct |
4 |
Correct |
656 ms |
1444 KB |
Output is correct |
5 |
Correct |
970 ms |
1448 KB |
Output is correct |
6 |
Correct |
824 ms |
1488 KB |
Output is correct |
7 |
Correct |
838 ms |
1452 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '10' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '10' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
526 ms |
1456 KB |
1st lines differ - on the 1st token, expected: '11903', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
290 ms |
568 KB |
1st lines differ - on the 1st token, expected: '7197', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '10' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
456 ms |
936 KB |
Output is correct |
2 |
Correct |
674 ms |
1468 KB |
Output is correct |
3 |
Correct |
787 ms |
1452 KB |
Output is correct |
4 |
Correct |
656 ms |
1444 KB |
Output is correct |
5 |
Correct |
970 ms |
1448 KB |
Output is correct |
6 |
Correct |
824 ms |
1488 KB |
Output is correct |
7 |
Correct |
838 ms |
1452 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '13', found: '10' |
12 |
Halted |
0 ms |
0 KB |
- |