| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1356364 | kawhiet | Sequence (APIO23_sequence) | C++20 | 63 ms | 31552 KiB |
#include <bits/stdc++.h>
#include "sequence.h"
using namespace std;
int sequence(int n, vector<int> a) {
vector<vector<int>> pos(n + 1);
for (int i = 0; i < n; i++) {
pos[a[i]].push_back(i);
}
int ans = 0;
for (int x = 1; x <= n; x++) {
if (pos[x].empty()) continue;
vector<int> s;
int c = 1;
for (int i = 1; i < pos[x].size(); i++) {
if (pos[x][i] == pos[x][i - 1] + 1) {
c++;
} else {
s.push_back(c);
c = 1;
}
}
s.push_back(c);
if (s.size() == 2) {
int left = pos[x][0];
int right = n - pos[x].back() - 1;
int len = pos[x].back() - pos[x][0] + 1;
int cnt = len - s[0] - s[1];
int l = 0, r = left + right + 1;
while (l + 1 < r) {
int m = (l + r) / 2;
if (m * 2 <= len + m) {
l = m;
} else {
r = m;
}
}
if (cnt * 2 <= len + l) {
ans = max(ans, s[0] + s[1]);
}
}
ans = max(ans, ranges::max(s));
}
return ans;
}| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
