#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
int n, K, w[3010], C[3010], S[3010], res, CC[3010], IT[3010], R[3010][3010];
void Do() {
int i, j;
for (i = 1; i <= n; i++) {
for (j = n; j >= i; j--) {
R[i][j] = 0;
if (w[i - 1] == w[j + 1] && i > 1 && j < n)R[i][j] = R[i - 1][j + 1] + 1;
}
}
for (i = 1; i < n; i++) {
int b = i;
for (j = 1; j <= K; j++)C[j] = 0;
set<int>Set;
C[w[b]]++;
Set.insert(w[b]);
while (b > 1 && w[b - 1] >= w[b]) {
b--;
C[w[b]]++;
Set.insert(w[b]);
}
for (j = 1; j <= K; j++){
S[j] = C[j];
S[j] += S[j - 1];
}
int small = -1, smallc = 0;
for (j = i + 1; j <= n; j++) {
if (w[i] > w[j]) {
if (small != -1) {
if (small == w[j])smallc++;
else break;
}
else {
small = w[j]; smallc = 1;
}
}
else {
if (!C[w[j]])Set.insert(w[j]);
C[w[j]]--;
if (!C[w[j]])Set.erase(w[j]);
}
int last = K;
if (!Set.empty()) last = *Set.begin();
else{
res = max(res, j - b + 1 + R[b][j] * 2);
}
res = max(res,S[last - 1] * 2 + (S[last] - S[last - 1] + min(0, -C[last]))*2 + smallc);
}
}
for (i = 2; i <= n+n; i++) {
int b = i / 2 + 1, e = i - i / 2 - 1;
while (b > 1 && e < n && w[b - 1] == w[e + 1])b--, e++;
int bb = b-1;
for (j = 1; j <= K; j++)C[j] = 0;
set<int>Set;
res = max(res, e - b + 1);
if (b == 1) continue;
int be = bb;
for (j = bb; j >= 1; j--) {
if (j != bb && w[j] < w[j + 1])break;
be = j;
C[w[j]]++;
Set.insert(w[j]);
}
for (j = 1; j <= K; j++) {
S[j] = C[j];
S[j] += S[j - 1];
}
for (j = e + 1; j <= n; j++) {
if (w[bb] > w[j])break;
if (!C[w[j]])Set.insert(w[j]);
C[w[j]]--;
if (!C[w[j]])Set.erase(w[j]);
int last = K;
if (!Set.empty()) last = *Set.begin();
else {
res = max(res, j - be + 1 + R[be][j] * 2);
}
res = max(res, S[last - 1] * 2 + (S[last] - S[last - 1] + min(0, -C[last]))*2 + e-b+1);
}
}
}
int Solve1() {
int i;
res = 0;
for (i = 1; i <= K; i++)C[i] = 0;
for (i = 1; i <= n; i++) {
C[w[i]]++;
res = max(res, C[w[i]]);
}
Do();
reverse(w + 1, w + n + 1);
for (i = 1; i <= n; i++)w[i] = K + 1 - w[i];
Do();
return res;
}
int main() {
int i, j;
scanf("%d%d", &n, &K);
for (i = 1; i <= n; i++)scanf("%d", &w[i]);
printf("%d\n", Solve1());
}
Compilation message
aaqqz.cpp: In function 'int main()':
aaqqz.cpp:101:9: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
aaqqz.cpp:102:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &K);
~~~~~^~~~~~~~~~~~~~~~
aaqqz.cpp:103:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (i = 1; i <= n; i++)scanf("%d", &w[i]);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
480 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
476 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
25 |
Correct |
2 ms |
476 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
256 KB |
Output is correct |
28 |
Correct |
2 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
504 KB |
Output is correct |
31 |
Correct |
2 ms |
504 KB |
Output is correct |
32 |
Correct |
2 ms |
504 KB |
Output is correct |
33 |
Correct |
2 ms |
504 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
36 |
Correct |
2 ms |
504 KB |
Output is correct |
37 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
480 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
476 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
25 |
Correct |
2 ms |
476 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
256 KB |
Output is correct |
28 |
Correct |
2 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
504 KB |
Output is correct |
31 |
Correct |
2 ms |
504 KB |
Output is correct |
32 |
Correct |
2 ms |
504 KB |
Output is correct |
33 |
Correct |
2 ms |
504 KB |
Output is correct |
34 |
Correct |
2 ms |
504 KB |
Output is correct |
35 |
Correct |
2 ms |
504 KB |
Output is correct |
36 |
Correct |
2 ms |
504 KB |
Output is correct |
37 |
Correct |
2 ms |
504 KB |
Output is correct |
38 |
Correct |
221 ms |
28172 KB |
Output is correct |
39 |
Correct |
215 ms |
28096 KB |
Output is correct |
40 |
Correct |
215 ms |
28024 KB |
Output is correct |
41 |
Correct |
403 ms |
28052 KB |
Output is correct |
42 |
Correct |
404 ms |
28052 KB |
Output is correct |
43 |
Correct |
255 ms |
28036 KB |
Output is correct |
44 |
Correct |
242 ms |
28024 KB |
Output is correct |
45 |
Correct |
259 ms |
28024 KB |
Output is correct |
46 |
Correct |
259 ms |
28024 KB |
Output is correct |
47 |
Correct |
379 ms |
28028 KB |
Output is correct |
48 |
Correct |
379 ms |
28024 KB |
Output is correct |
49 |
Correct |
275 ms |
28024 KB |
Output is correct |
50 |
Correct |
273 ms |
28024 KB |
Output is correct |
51 |
Correct |
375 ms |
28080 KB |
Output is correct |
52 |
Correct |
403 ms |
28084 KB |
Output is correct |
53 |
Correct |
241 ms |
28036 KB |
Output is correct |
54 |
Correct |
240 ms |
28044 KB |
Output is correct |
55 |
Correct |
320 ms |
27996 KB |
Output is correct |
56 |
Correct |
273 ms |
28096 KB |
Output is correct |
57 |
Correct |
287 ms |
28092 KB |
Output is correct |
58 |
Correct |
475 ms |
27956 KB |
Output is correct |
59 |
Correct |
472 ms |
28072 KB |
Output is correct |
60 |
Correct |
244 ms |
28104 KB |
Output is correct |
61 |
Correct |
244 ms |
28152 KB |
Output is correct |
62 |
Correct |
368 ms |
28024 KB |
Output is correct |
63 |
Correct |
372 ms |
28152 KB |
Output is correct |
64 |
Correct |
2832 ms |
28168 KB |
Output is correct |
65 |
Correct |
2471 ms |
28160 KB |
Output is correct |
66 |
Correct |
2003 ms |
28140 KB |
Output is correct |
67 |
Correct |
1737 ms |
28136 KB |
Output is correct |