이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "sequence.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
int sequence(int n, vector<int> A)
{
int ans = 1;
for (int i = 0; i < n; i++)
{
ordered_set hm;
for (int j = i; j < n; j++)
{
hm.insert(A[j]);
int x = *hm.find_by_order((j - i) / 2);
int y = *hm.find_by_order((j - i + 1) / 2);
ans = max(ans, (int)hm.order_of_key(x + 1) - (int)hm.order_of_key(x));
ans = max(ans, (int)hm.order_of_key(y + 1) - (int)hm.order_of_key(y));
}
}
bool works = 1;
int last = 0;
for (int i = 0; i < n; i++)
{
if (last > A[i])
{
for (int j = i; j < n; j++)
{
if (last < A[i])
works = 0;
last = A[i];
}
break;
}
last = A[i];
}
if (!works)
return ans;
last = 0;
vector<int> cnt(n + 1);
for (int i = 0; i < n; i++)
{
if (last > A[i])
break;
cnt[A[i]]++;
ans = max(ans, cnt[A[i]]);
last = A[i];
}
last = 0;
for (int i = 1; i <= n; i++)
cnt[i] = 0;
for (int i = n - 1; i >= 0; i--)
{
if (last > A[i])
break;
last = A[i];
cnt[A[i]]++;
ans = max(ans, cnt[A[i]]);
}
for (int i = 1; i <= n; i++)
cnt[i] = 0;
sort(A.begin(), A.end());
for (int i = 0; i < n; i++)
cnt[A[i]]++;
for (int i = n / 2; i < n; i++)
ans = max(ans, cnt[A[i]]);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |