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.
A suggestion only fails if the suggested game is liked by the speaker but not by the other person.
Split the games into three groups: Alice-only, Bob-only, and common. A common game always ends the process immediately.
Let be the number of Alice-only games and be the number of Bob-only games. Before the last suggestion, Alice can only spend Alice-only games, and Bob can only spend Bob-only games.
Since Alice starts, if Alice has only failing moves available, the process cannot last past suggestions. Since Bob moves second and has failing moves, it cannot last past suggestions.
Both bounds are tight, so the answer is simply .
The annoying-looking part is the alternating game process, but the actual structure is tiny.
A suggestion can have only two outcomes:
So the common games are not something we count one by one. The first common game suggested is the final move. Boom, game over.
Define:
These are the only games that can be used as failed suggestions.
Upper bound from Alice
Alice moves on turns .
Alice can make at most failed suggestions, because every failed Alice suggestion must be Alice-only. After she uses all Alice-only games, her next suggestion must be common, so the process ends.
That means the total number of suggestions can never exceed:
Why? Alice can fail on her first turns, Bob can move between them, and then Alice ends it on her next turn.
Upper bound from Bob
Bob moves on turns .
Bob can make at most failed suggestions. After that, Bob's next suggestion must be common and end the process.
Since Bob moves second, this gives another upper bound:
So no strategy can beat:
Now we need to check this is actually achievable, not just a pretty formula doing cosplay as a proof.
Construction
If :
Alice uses all Alice-only games on her turns. Bob has at least Bob-only games, so he can answer each time with a failed Bob-only suggestion. Then Alice suggests any common game.
Total:
If :
Bob is the limiting side. Bob uses all Bob-only games, while Alice uses Alice-only games. This is possible because , so Alice has at least Alice-only games. Then Bob suggests a common game.
Total:
That exactly matches the upper bound, so the answer is:
The sorted order of the input is basically decorative here. Nice of it to show up dressed formally, but we only care about membership.
#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, m;
cin >> n >> m;
vector<int> inA(101, 0), inB(101, 0);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
inA[x] = 1;
}
for (int i = 0; i < m; i++) {
int x;
cin >> x;
inB[x] = 1;
}
int onlyA = 0, onlyB = 0;
for (int v = 1; v <= 100; v++) {
if (inA[v] && !inB[v]) onlyA++;
if (inB[v] && !inA[v]) onlyB++;
}
cout << min(2 * onlyA + 1, 2 * onlyB + 2) << '\n';
}
}#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, m;
cin >> n >> m;
vector<int> inA(101, 0), inB(101, 0);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
inA[x] = 1;
}
for (int i = 0; i < m; i++) {
int x;
cin >> x;
inB[x] = 1;
}
int onlyA = 0, onlyB = 0;
for (int v = 1; v <= 100; v++) {
if (inA[v] && !inB[v]) onlyA++;
if (inB[v] && !inA[v]) onlyB++;
}
cout << min(2 * onlyA + 1, 2 * onlyB + 2) << '\n';
}
}