#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
template <typename T> inline void read (T &x) {
char ch;
while (!isdigit(ch = getchar()) && ch != '-') ;
bool sign = ch == '-';
x = isdigit(ch) ? ch - '0' : 0;
while (isdigit(ch = getchar()))
x = x * 10 + ch - '0';
if (sign)
x = -x;
}
template <typename T> inline void write_pos (T x) {
if (x > 9) {
write_pos(x / 10);
}
putchar(x % 10 + '0');
}
template <typename T> inline void write (T x) {
if (x < 0)
putchar('-'), x = -x;
write_pos(x);
}
int n;
int a[N];
int b[N];
int cnt[N];
void read_input() {
read(n);
for (int i = 1; i <= n; i++) {
read(a[i]);
b[i] = a[i];
}
}
bool boring (int L, int R, int turn = 0) {
if (L >= R)
return false;
for (int i = L; i <= R; i++)
cnt[a[i]] = 0;
for (int i = L; i <= R; i++)
cnt[a[i]]++;
turn = rand() % 2;
if (!turn) {
for (int i = L; i <= R; i++)
if (cnt[a[i]] == 1)
return boring(L, i - 1, turn^1) || boring(i + 1, R, turn);
}
else {
for (int i = R; i >= L; i--)
if (cnt[a[i]] == 1)
return boring(L, i - 1, turn) || boring(i + 1, R, turn^1);
}
return true;
}
void solve() {
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;
cnt[a[i]] = 0;
}
puts(!boring(1, n) ? "non-boring" : "boring");
}
int main() {
// freopen("NONBORING.INP", "r", stdin);
// freopen("NONBORING.OUT", "w", stdout);
srand(time(NULL));
int t;
read(t);
while (t--) {
read_input();
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
972 KB |
Output is correct |
2 |
Execution timed out |
5085 ms |
2248 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |