# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
127878 |
2019-07-10T07:52:05 Z |
이온조(#3109) |
JOI15_aaqqz (JOI15_aaqqz) |
C++14 |
|
1109 ms |
9424 KB |
#include <bits/stdc++.h>
using namespace std;
int N, C, A[3009], U[3009], ans;
bool D[3009][3009];
void go(int s, int e) {
if(s < 0 || N < e || s > e) return;
int p = -1;
vector<int> T;
for(int i=s-1; i>=1; i--) {
if(p == -1 || p <= A[i]) {
T.push_back(A[i]);
p = A[i];
}
else break;
}
int l = 0, r = (int)T.size() - 1;
while(l <= r) {
int m = l+r >> 1;
vector<int> H(C+1, 0);
for(int i=0; i<=m; i++) ++H[T[i]];
int c = 0;
bool f = 1, sr = 1;
for(int i=e+1; i<=N && c<=m; i++) {
if(H[A[i]]) {
--H[A[i]];
++c;
}
else {
sr = 0;
if(A[i] < T[m]) f = 0;
}
}
f &= (c > m);
if(f) {
int L = s - m - 1, R = e + m + 1;
if(sr) while(A[L-1] == A[R+1]) --L, ++R;
ans = max(ans, R-L+1);
}
if(f) l = m+1;
else r = m-1;
}
}
void Do(int s, bool SR) {
int p = -1;
vector<int> T;
for(int i=s-1; i>=1; i--) {
if(p == -1 || p <= A[i]) {
T.push_back(A[i]);
p = A[i];
}
else break;
}
if(T.empty()) return;
int mn = T[0];
for(int i=s; i<=N; i++) if(T[0] > A[i]) {mn = A[i]; break;}
int l = 0, r = (int)T.size() - 1;
while(l <= r) {
int m = l+r >> 1;
vector<int> H(C+1, 0);
for(int i=0; i<=m; i++) ++H[T[i]];
int c = 0, mnc = 0;
bool f = 1, sr = 1;
for(int i=s; i<=N; i++) {
if(H[A[i]]) {
--H[A[i]];
++c;
}
else if(A[i] == mn) ++mnc;
else {
if(sr && SR && c > m) break;
sr = 0;
if(A[i] < T[m]) break;
}
}
f &= (c > m);
if(f) {
int L = s - m - 1, R = s + m + mnc;
// printf("[%d, %d]\n", L, R);
if(sr) while(A[L-1] == A[R+1]) --L, ++R;
// printf("s: %d, SR: %d, sr: %d, m: %d, [%d, %d]\n", s, SR, sr, m, L, R);
ans = max(ans, R-L+1);
}
if(f) l = m+1;
else r = m-1;
}
}
void solve() {
for(int i=N; i>=1; i--) {
for(int j=i; j<=N; j++) {
if(i+1 >= j && A[i] == A[j]) D[i][j] = 1;
else if(D[i+1][j-1] && A[i] == A[j]) D[i][j] = 1;
else D[i][j] = 0;
if(D[i][j]) ans = max(ans, j-i+1);
}
}
for(int i=1; i<=N; i++) {
int l = i, r = i;
while(D[l-1][r+1]) --l, ++r;
go(l, r);
l = i, r = i-1;
while(D[l-1][r+1]) --l, ++r;
go(l, r);
Do(i, 0);
Do(i, 1);
}
}
int main() {
scanf("%d%d",&N,&C);
A[0] = 1e9;
for(int i=1; i<=N; i++) {
scanf("%d",&A[i]);
++U[A[i]];
}
for(int i=1; i<=C; i++) ans = max(ans, U[i]);
solve();
reverse(A+1, A+N+1);
for(int i=1; i<=N; i++) A[i] = C - A[i] + 1;
solve();
printf("%d", ans);
return 0;
}
Compilation message
aaqqz.cpp: In function 'void go(int, int)':
aaqqz.cpp:22:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l+r >> 1;
~^~
aaqqz.cpp: In function 'void Do(int, bool)':
aaqqz.cpp:67:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l+r >> 1;
~^~
aaqqz.cpp: In function 'int main()':
aaqqz.cpp:121:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&N,&C);
~~~~~^~~~~~~~~~~~~~
aaqqz.cpp:124:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&A[i]);
~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 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 |
476 KB |
Output is correct |
14 |
Correct |
2 ms |
508 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
488 KB |
Output is correct |
17 |
Correct |
2 ms |
476 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 |
508 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 |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
25 |
Correct |
2 ms |
504 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
376 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 |
508 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 |
476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 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 |
476 KB |
Output is correct |
14 |
Correct |
2 ms |
508 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
488 KB |
Output is correct |
17 |
Correct |
2 ms |
476 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 |
508 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 |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
25 |
Correct |
2 ms |
504 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
376 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 |
508 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 |
476 KB |
Output is correct |
38 |
Correct |
71 ms |
9252 KB |
Output is correct |
39 |
Correct |
55 ms |
9424 KB |
Output is correct |
40 |
Correct |
55 ms |
9208 KB |
Output is correct |
41 |
Correct |
192 ms |
9256 KB |
Output is correct |
42 |
Correct |
192 ms |
9268 KB |
Output is correct |
43 |
Correct |
80 ms |
9248 KB |
Output is correct |
44 |
Correct |
80 ms |
9248 KB |
Output is correct |
45 |
Correct |
101 ms |
9256 KB |
Output is correct |
46 |
Correct |
100 ms |
9308 KB |
Output is correct |
47 |
Correct |
106 ms |
9248 KB |
Output is correct |
48 |
Correct |
106 ms |
9264 KB |
Output is correct |
49 |
Correct |
104 ms |
9256 KB |
Output is correct |
50 |
Correct |
104 ms |
9288 KB |
Output is correct |
51 |
Correct |
113 ms |
9340 KB |
Output is correct |
52 |
Correct |
114 ms |
9168 KB |
Output is correct |
53 |
Correct |
71 ms |
9244 KB |
Output is correct |
54 |
Correct |
71 ms |
9208 KB |
Output is correct |
55 |
Correct |
1109 ms |
9308 KB |
Output is correct |
56 |
Correct |
106 ms |
9208 KB |
Output is correct |
57 |
Correct |
106 ms |
9252 KB |
Output is correct |
58 |
Correct |
125 ms |
9336 KB |
Output is correct |
59 |
Correct |
126 ms |
9208 KB |
Output is correct |
60 |
Correct |
86 ms |
9208 KB |
Output is correct |
61 |
Correct |
85 ms |
9208 KB |
Output is correct |
62 |
Correct |
112 ms |
9284 KB |
Output is correct |
63 |
Correct |
112 ms |
9208 KB |
Output is correct |
64 |
Correct |
101 ms |
9240 KB |
Output is correct |
65 |
Correct |
103 ms |
9208 KB |
Output is correct |
66 |
Correct |
110 ms |
9308 KB |
Output is correct |
67 |
Correct |
113 ms |
9248 KB |
Output is correct |