#include "towers.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using ii = pair <ll, ll>;
using vii = vector <ii>;
using vi = vector <int>;
ll n, k;
vll ve;
void init (int n, vi ve) {
::n = n;
k = 0;
::ve = vll(ve.begin(), ve.end());
while (ve[k] < ve[k+1]) k++;
}
const ll MAXN = 2E3+16;
ll dp[MAXN];
int max_towers (int ql, int qr, int d) {
fill(dp+ql, dp+qr+1, 0);
// cerr << d << '\n';
for (ll i = ql; i <= qr; i++) {
ii maxN = { 0, -16 };
dp[i] = 1;
for (ll j = i-1; j >= ql; j--) {
if (ve[i] <= maxN.first-d)
if (ve[j] <= maxN.first-d) {
dp[i] = max(dp[i], dp[j]+1);
break;
}
maxN = max(maxN, ii{ ve[j], j });
}
// cerr << ve[i] << ": " << dp[i] << '\n';
}
// return *max_element(dp+ql, dp+qr+1);
// fill(dp+ql, dp+qr+1, 0);
// deque <ii> dq;
// for (ll i = ql; i <= qr; i++) {
// dp[i] = 1;
// while (dq.size() && dq.front().first < ve[i]) dq.pop_front();
// // ll j = lower_bound(dq.begin(), dq.end(), ii{ ve[i]+d, 0 }) - dq.begin();
// // j++;
// // if (j < dq.size()) dp[i] = max(dp[i], dq[j].second+1);
// // cerr << ve[i] << ": " << dp[i] << '\n';
// // cerr << "j " << j << " ";
// dq.push_front({ ve[i], dq.size() ? max(dq.front().second, dp[i]) : dp[i] });
// for (auto [v1, v2] : dq) cerr << v1 << ' ' << v2 << " ";
// cerr << '\n';
// // for (ll j = i-1; j >= ql; j--) {
// // if (ve[i] <= maxN.first-d)
// // if (ve[j] <= maxN.first-d) dp[i] = max(dp[i], dp[j]+1);
// // maxN = max(maxN, ii{ ve[j], j });
// // }
// }
return *max_element(dp+ql, dp+qr+1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
1900 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '12' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '12' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
2772 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
1112 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '12' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
1900 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |