# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
128125 | 2019-07-10T12:48:13 Z | ainta | JOI15_aaqqz (JOI15_aaqqz) | C++17 | 2 ms | 376 KB |
#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(); for (i = 1; i <= n; i++)reverse(w + 1, w + n + 1); Do(); printf("%d\n", res); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |