#include "sequence.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int MAX_N = 5e5 + 5;
int n;
int a[MAX_N];
vector<pii> ranges[MAX_N];
void precomp() {
int i = 1;
while (i != n + 1) {
int j = i;
while (j < n && a[j + 1] == a[i]) j++;
ranges[a[i]].push_back({i, j});
i = j + 1;
}
}
int sequence(int tmp_n, vector<int> tmp_a) {
n = tmp_n;
for (int i = 0; i < n; i++) a[i + 1] = tmp_a[i];
precomp();
int ans = 0;
for (int i = 1; i <= n; i++) {
if (ranges[i].empty()) continue;
for (pii x : ranges[i]) ans = max(ans, x.second - x.first + 1);
if (ranges[i].size() == 1) continue;
assert(ranges[i].size() == 2);
int range_size = 0;
for (pii x : ranges[i]) range_size += x.second - x.first + 1;
int in_size = ranges[i][1].first - ranges[i][0].second + 1;
int out_size = ranges[i][0].first - 1 + n - ranges[i][1].second;
if (out_size >= in_size - range_size) ans = max(ans, range_size);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13144 KB |
Output is correct |
2 |
Runtime error |
12 ms |
25732 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13144 KB |
Output is correct |
2 |
Runtime error |
12 ms |
25732 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13144 KB |
Output is correct |
2 |
Correct |
60 ms |
27732 KB |
Output is correct |
3 |
Correct |
60 ms |
27728 KB |
Output is correct |
4 |
Correct |
34 ms |
17948 KB |
Output is correct |
5 |
Correct |
59 ms |
26704 KB |
Output is correct |
6 |
Correct |
56 ms |
26908 KB |
Output is correct |
7 |
Correct |
35 ms |
18000 KB |
Output is correct |
8 |
Correct |
35 ms |
18004 KB |
Output is correct |
9 |
Correct |
37 ms |
18008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
12 ms |
25732 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
87 ms |
33580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13144 KB |
Output is correct |
2 |
Runtime error |
12 ms |
25732 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13144 KB |
Output is correct |
2 |
Runtime error |
12 ms |
25732 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |