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.
Start with the obvious insta-win: if there are at most ones, Alice can pick all of them in her subsequence and the game ends right there.
If Alice does not win immediately, then after her move at least one remains. Bob only needs to make sure Alice never starts a turn with at most ones.
The real split is whether Bob can choose a length- substring that avoids a surviving . If yes, he can create fresh ones while keeping that old one alive.
When , every position is outside at least one length- substring. So Bob can always avoid one surviving and give Alice at least ones again.
When , Alice can use her first move to make the remaining ones fit inside some length- substring after Bob moves. Then her next move clears that whole substring.
The main trap is overthinking the game. Alice only wins right after one of her own moves, because Bob's move only creates ones. So the key question is:
Can Alice ever start a turn with at most ones?
If yes, she chooses all those ones in her subsequence, pads with any zeros if needed, and wins immediately.
So first:
Now assume the string has more than ones initially.
When , Bob wins
After any Alice move, if she has not won, at least one remains. Say one such remaining one is at position .
Bob wants to choose a length- substring that avoids . If he can do that, then after his move there are at least:
These are disjoint, so Alice faces at least ones and cannot clear everything next turn.
When , Bob can always avoid any fixed position :
Both are valid, and one avoids .
Therefore Bob can repeat this forever. Alice never gets a turn with at most ones. Bob wins.
When , Alice wins
Now the board is short enough that Bob cannot freely avoid everything. Alice can force a two-move win.
On her first move, Alice chooses a subsequence of length . Since , the number of unchosen positions is less than .
Alice chooses her subsequence so that all remaining ones, if any, lie among the unchosen positions. After her move, there are fewer than positions where old ones may remain.
Then Bob chooses some substring of length and sets it to .
After Bob's move, every is either:
But Alice can choose her first move so that the old survivors are placed inside a block Bob cannot avoid when . Equivalently, with , the string is too short for Bob to make a disjoint block of new ones while preserving an extra old one outside. His move cannot force Alice to face more than one length- block of ones.
So after Bob's move, all ones fit inside some length- substring. Alice chooses those positions on her next turn and turns them all to zero.
That gives the full decision rule:
Otherwise, Bob wins. Short condition, nasty little game. Classic Codeforces: the whole battle is just whether Bob has enough room to dodge one survivor.
#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, k;
string s;
cin >> n >> k >> s;
int ones = 0;
for (char c : s) ones += (c == '1');
if (ones <= k || 2 * k > n) {
cout << "Alice\n";
} else {
cout << "Bob\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, k;
string s;
cin >> n >> k >> s;
int ones = 0;
for (char c : s) ones += (c == '1');
if (ones <= k || 2 * k > n) {
cout << "Alice\n";
} else {
cout << "Bob\n";
}
}
}