Search for a command to run...
Progressive hints first, then the full explanation and implementation when you're ready to cash out.
Review status
AI-generated and still unreviewed. Double-check the details before internalizing them.
Hints
Open only as much as you need to keep the solve alive.
The circle and infinite walking sound scary, but ask yourself: what actually restricts eating apples? Is it position, or beauty value?
Once you eat beauty , you can never eat beauty again, and you can never eat anything smaller. Equal values are dead forever too.
So the answer can never be bigger than the number of distinct beauty values in the array. Two apples with the same beauty cannot both appear in a strictly increasing eaten sequence.
Can you always achieve all distinct values? Yes: eat them in increasing order of beauty. Since you walk forever and may skip anything, you can always wait until you see some apple with the next needed beauty.
So the whole problem collapses to: count distinct values in . The circle is mostly a psychological trap. A very polite one, but still a trap.
The key is to separate the real rule from the noisy story.
You walk around a circle forever, and at every tree you may skip the apple. You may only eat an apple if its beauty is strictly greater than the beauty of the last apple you ate.
That means the beauties of eaten apples must form a strictly increasing sequence.
So immediately:
Why? Because if two apples have the same beauty , you cannot eat both. After eating the first , the second is not strictly greater than .
Now the only question: can we always eat one apple of every distinct beauty?
Yes.
Suppose the distinct beauties are:
We can choose to eat them in exactly that order.
Start walking. Skip everything until you see some apple with beauty , then eat it. After that, keep walking and skip everything until you see some apple with beauty , then eat it. Repeat for .
Because the path loops forever, every tree will be visited again and again. So no matter where the next needed beauty is, you will eventually reach it. Skipping earlier apples is allowed, so position cannot block you.
This proves:
That's it. The circle is basically decorative furniture. Count unique numbers and leave.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
set<int> seen;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
seen.insert(x);
}
cout << seen.size() << '\n';
}
return 0;
}#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
set<int> seen;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
seen.insert(x);
}
cout << seen.size() << '\n';
}
return 0;
}