# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
798221 | hungnt | Non-boring sequences (CERC12_D) | C++14 | 284 ms | 17096 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n;
int a[N], b[N], pos[N];
int low[N], high[N];
bool boring(int L, int R)
{
if(L >= R) return 0;
int curL = L, curR = R;
bool x = 0;
while(curL <= curR)
{
if (!x)
{
if (low[curL] < L && high[curL] > R)
return boring(L, curL - 1) || boring(curL + 1, R);
++curL;
}
else {
if (low[curR] < L && high[curR] > R)
return boring(L, curR - 1) || boring(curR + 1, R);
--curR;
}
x ^= 1;
}
return 1;
}
void process()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
b[i] = a[i];
}
sort(b + 1, b + n + 1);
for(int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
for(int i = 1; i <= n; i++) pos[i] = 0;
for(int i = 1; i <= n; i++)
{
low[i] = pos[a[i]];
pos[a[i]] = i;
}
for(int i = 1; i <= n; i++) pos[i] = n + 1;
for(int i = n; i >= 1; i--)
{
high[i] = pos[a[i]];
pos[a[i]] = i;
}
cout << (boring(1, n) ? "boring\n" : "non-boring\n");
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while(t--) process();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |