#ifndef SorahISA
#define SorahISA
#include SorahISA __FILE__ SorahISA
void solve() {
int N, D; cin >> N >> D;
vector<int> A(N);
for (int &x : A) cin >> x;
if (D == 1) {
int ans = 1;
deque<int> stk;
for (int i = N-1; i >= 0; --i) {
while (SZ(stk) and A[i] >= stk[0]) stk.pf();
stk.ef(A[i]);
chmax(ans, SZ(stk));
}
cout << ans << "\n";
}
else if (D == N) {
reverse(ALL(A));
for (int &x : A) x *= -1;
vector<int> lis{0};
for (int x : A) {
if (x > lis.back()) lis.eb(x);
else *lower_bound(ALL(lis), x) = x;
}
cout << SZ(lis) << "\n";
}
else {
vector<int> dp(N, 1);
for (int i = N-1; i >= 0; --i) {
for (int j = i+1, cnt = 1; cnt <= D and j < N; ++j, ++cnt) {
if (A[j] > A[i]) chmax(dp[i], dp[j] + 1);
else if (A[j] == A[i]) chmax(dp[i], dp[j]), cnt = 0;
else if (A[j] < A[i]) cnt = 0;
}
// debug(i, A[i], dp[i]);
}
cout << *max_element(ALL(dp)) << "\n";
}
}
int32_t main() {
fastIO();
int t = 1; // cin >> t;
for (int _ = 1; _ <= t; ++_) {
solve();
}
return 0;
}
#else
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
using float80 = long double;
#define double float80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())
#ifdef local
#define fastIO() void()
#define debug(...) \
fprintf(stderr, "\u001b[33m"), \
fprintf(stderr, "At [%s], line %d: (%s) = ", __FUNCTION__, __LINE__, #__VA_ARGS__), \
_do(__VA_ARGS__), \
fprintf(stderr, "\u001b[0m")
template <typename T> void _do(T &&_t) { cerr << _t << "\n"; }
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) { cerr << _t << ", ", _do(_u...); }
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#endif
template <typename T, typename U> bool chmin(T &lhs, U rhs) { return lhs > rhs ? lhs = rhs, 1 : 0; }
template <typename T, typename U> bool chmax(T &lhs, U rhs) { return lhs < rhs ? lhs = rhs, 1 : 0; }
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
456 KB |
Output is correct |
31 |
Correct |
1 ms |
452 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
456 KB |
Output is correct |
31 |
Correct |
1 ms |
452 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
2 ms |
464 KB |
Output is correct |
43 |
Correct |
16 ms |
604 KB |
Output is correct |
44 |
Correct |
39 ms |
604 KB |
Output is correct |
45 |
Correct |
65 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
4 ms |
604 KB |
Output is correct |
48 |
Correct |
17 ms |
604 KB |
Output is correct |
49 |
Correct |
27 ms |
604 KB |
Output is correct |
50 |
Correct |
31 ms |
600 KB |
Output is correct |
51 |
Correct |
1 ms |
460 KB |
Output is correct |
52 |
Correct |
2 ms |
604 KB |
Output is correct |
53 |
Correct |
1 ms |
604 KB |
Output is correct |
54 |
Correct |
3 ms |
584 KB |
Output is correct |
55 |
Correct |
59 ms |
604 KB |
Output is correct |
56 |
Correct |
36 ms |
848 KB |
Output is correct |
57 |
Correct |
36 ms |
856 KB |
Output is correct |
58 |
Correct |
20 ms |
604 KB |
Output is correct |
59 |
Correct |
20 ms |
604 KB |
Output is correct |
60 |
Correct |
25 ms |
600 KB |
Output is correct |
61 |
Correct |
26 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
2652 KB |
Output is correct |
2 |
Correct |
26 ms |
2648 KB |
Output is correct |
3 |
Correct |
25 ms |
2652 KB |
Output is correct |
4 |
Correct |
25 ms |
2648 KB |
Output is correct |
5 |
Correct |
25 ms |
2816 KB |
Output is correct |
6 |
Correct |
25 ms |
2648 KB |
Output is correct |
7 |
Correct |
24 ms |
5212 KB |
Output is correct |
8 |
Correct |
28 ms |
2648 KB |
Output is correct |
9 |
Correct |
24 ms |
4436 KB |
Output is correct |
10 |
Correct |
27 ms |
2652 KB |
Output is correct |
11 |
Correct |
25 ms |
2652 KB |
Output is correct |
12 |
Correct |
25 ms |
2652 KB |
Output is correct |
13 |
Correct |
23 ms |
2648 KB |
Output is correct |
14 |
Correct |
24 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
2648 KB |
Output is correct |
2 |
Correct |
33 ms |
2648 KB |
Output is correct |
3 |
Correct |
37 ms |
2652 KB |
Output is correct |
4 |
Correct |
37 ms |
2652 KB |
Output is correct |
5 |
Correct |
35 ms |
3804 KB |
Output is correct |
6 |
Correct |
38 ms |
2824 KB |
Output is correct |
7 |
Correct |
24 ms |
8312 KB |
Output is correct |
8 |
Correct |
23 ms |
2652 KB |
Output is correct |
9 |
Correct |
35 ms |
3692 KB |
Output is correct |
10 |
Correct |
35 ms |
2808 KB |
Output is correct |
11 |
Correct |
38 ms |
2836 KB |
Output is correct |
12 |
Correct |
24 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
456 KB |
Output is correct |
31 |
Correct |
1 ms |
452 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
2 ms |
464 KB |
Output is correct |
43 |
Correct |
16 ms |
604 KB |
Output is correct |
44 |
Correct |
39 ms |
604 KB |
Output is correct |
45 |
Correct |
65 ms |
604 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
4 ms |
604 KB |
Output is correct |
48 |
Correct |
17 ms |
604 KB |
Output is correct |
49 |
Correct |
27 ms |
604 KB |
Output is correct |
50 |
Correct |
31 ms |
600 KB |
Output is correct |
51 |
Correct |
1 ms |
460 KB |
Output is correct |
52 |
Correct |
2 ms |
604 KB |
Output is correct |
53 |
Correct |
1 ms |
604 KB |
Output is correct |
54 |
Correct |
3 ms |
584 KB |
Output is correct |
55 |
Correct |
59 ms |
604 KB |
Output is correct |
56 |
Correct |
36 ms |
848 KB |
Output is correct |
57 |
Correct |
36 ms |
856 KB |
Output is correct |
58 |
Correct |
20 ms |
604 KB |
Output is correct |
59 |
Correct |
20 ms |
604 KB |
Output is correct |
60 |
Correct |
25 ms |
600 KB |
Output is correct |
61 |
Correct |
26 ms |
604 KB |
Output is correct |
62 |
Correct |
28 ms |
2652 KB |
Output is correct |
63 |
Correct |
26 ms |
2648 KB |
Output is correct |
64 |
Correct |
25 ms |
2652 KB |
Output is correct |
65 |
Correct |
25 ms |
2648 KB |
Output is correct |
66 |
Correct |
25 ms |
2816 KB |
Output is correct |
67 |
Correct |
25 ms |
2648 KB |
Output is correct |
68 |
Correct |
24 ms |
5212 KB |
Output is correct |
69 |
Correct |
28 ms |
2648 KB |
Output is correct |
70 |
Correct |
24 ms |
4436 KB |
Output is correct |
71 |
Correct |
27 ms |
2652 KB |
Output is correct |
72 |
Correct |
25 ms |
2652 KB |
Output is correct |
73 |
Correct |
25 ms |
2652 KB |
Output is correct |
74 |
Correct |
23 ms |
2648 KB |
Output is correct |
75 |
Correct |
24 ms |
2648 KB |
Output is correct |
76 |
Correct |
24 ms |
2648 KB |
Output is correct |
77 |
Correct |
33 ms |
2648 KB |
Output is correct |
78 |
Correct |
37 ms |
2652 KB |
Output is correct |
79 |
Correct |
37 ms |
2652 KB |
Output is correct |
80 |
Correct |
35 ms |
3804 KB |
Output is correct |
81 |
Correct |
38 ms |
2824 KB |
Output is correct |
82 |
Correct |
24 ms |
8312 KB |
Output is correct |
83 |
Correct |
23 ms |
2652 KB |
Output is correct |
84 |
Correct |
35 ms |
3692 KB |
Output is correct |
85 |
Correct |
35 ms |
2808 KB |
Output is correct |
86 |
Correct |
38 ms |
2836 KB |
Output is correct |
87 |
Correct |
24 ms |
2904 KB |
Output is correct |
88 |
Correct |
338 ms |
5212 KB |
Output is correct |
89 |
Correct |
1249 ms |
5144 KB |
Output is correct |
90 |
Execution timed out |
4065 ms |
4948 KB |
Time limit exceeded |
91 |
Halted |
0 ms |
0 KB |
- |