#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
int n, K, w[3010], C[3010], S[3010], res, CC[3010], IT[3010];
void Do() {
int i, j;
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();
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;
for (j = bb; j >= 1; j--) {
if (j != bb && w[j] < w[j + 1])break;
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();
res = max(res, S[last - 1] * 2 + (S[last] - S[last - 1] + min(0, -C[last]))*2 + e-b+1);
}
}
}
int main() {
int i, j;
scanf("%d%d", &n, &K);
for (i = 1; i <= n; i++) {
scanf("%d", &w[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();
printf("%d\n", res);
}
Compilation message
aaqqz.cpp: In function 'int main()':
aaqqz.cpp:73:9: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
aaqqz.cpp:74: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:76:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &w[i]);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
424 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
424 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
380 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |