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.
Track columns before rows. A move removes one token from its starting column and only creates tokens in smaller columns, so the game always ends.
Column is dead. Tokens there never move, so they should not affect the winner.
When , every token has exactly one possible path. So there is no strategy, just a fixed number of total turns.
When , the second row is basically a parity switch. In each smaller column, a path can add either token or tokens while continuing left.
For , the losing states are exactly those where every column has an even number of tokens. From the largest odd column, you can build one move that fixes every smaller column's parity too.
Forget the picture for a second. The important object is not the exact pile layout inside each cell. It is the number of tokens in each column.
Let be the number of tokens currently in column .
A move starting from column removes one token from column , and because the first step must go left, it never adds anything back to column . It may add tokens only in columns .
So the game cannot run forever: if you look at
each move decreases the first changed entry in this high-to-low order. No infinite nonsense, no draw, normal game.
Case 1:
There is only one row, so a token in column has only one valid move:
Column tokens are dead.
Let be the number of future turns caused by one token initially in column .
Clearly:
For , moving that token takes one turn and creates one token in every smaller column:
This gives:
Only is odd. Every token in column or later contributes an even number of turns. Since there is no real choice in this one-row game, the winner is just determined by the parity of the total number of turns.
So for , Mimo wins iff the number of tokens in column is odd.
Case 2:
Now the clean claim is:
Yuyu wins exactly when every column contains an even number of tokens.
Column still does not matter, because tokens there cannot move.
First, suppose every for is even. Any legal move must start in some column . That move removes one token from column , and adds nothing back to column . Therefore becomes odd. So the player who moves from this state always gives the opponent a state with at least one odd non-dead column.
Now suppose some column has odd token count. Let be the largest such column. We will move a token from column and make every non-dead column even.
Columns larger than are already even and will not be touched. Removing one token from column makes even. For each smaller column with , we want to add:
Then every such column becomes even.
Why is this path always possible? Because gives us two adjacent rows to snake through. Start from the chosen token at row , column . Pick a neighboring row : if , use , otherwise use .
After stepping left into column , process columns from right to left:
That uses either one or two distinct cells in each column, never moves right, and eventually reaches column . Column can receive whatever; it is dead anyway.
So every state with at least one odd column has a move to the all-even state. And every all-even state moves to a not-all-even state.
That is the whole game. No full Grundy table needed. Trying to compute one is bringing a spreadsheet to a knife fight.
Algorithm
For each test case:
Mimo; otherwise print Yuyu.The total number of tokens over all tests is at most , so an parity set is easily fast enough.
#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--) {
ll n, m, k;
cin >> n >> m >> k;
set<int> odd;
for (int i = 0; i < k; i++) {
int x, y;
cin >> x >> y;
bool relevant = (n == 1 ? y == 2 : y >= 2);
if (!relevant) continue;
if (odd.count(y)) odd.erase(y);
else odd.insert(y);
}
cout << (odd.empty() ? "Yuyu" : "Mimo") << '\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--) {
ll n, m, k;
cin >> n >> m >> k;
set<int> odd;
for (int i = 0; i < k; i++) {
int x, y;
cin >> x >> y;
bool relevant = (n == 1 ? y == 2 : y >= 2);
if (!relevant) continue;
if (odd.count(y)) odd.erase(y);
else odd.insert(y);
}
cout << (odd.empty() ? "Yuyu" : "Mimo") << '\n';
}
}