#include <bits/stdc++.h>
using namespace std;
const int maxa = 1e5 + 5, maxb = 50;
int a, b, n, f[maxa][maxb];
int dfs(int x, int y) {
if (pow(x, y) >= n) return f[x][y] = 2;
if (f[x][y]) return f[x][y];
return f[x][y] = 3 - min(dfs(x, y + 1), dfs(x+ 1, y));
}
string s[3] = {"Missing", "Stas", "Masha"};
int main() {
cin >> a >> b >> n;
if (a == 1 and pow(2, b) >= n) return puts("Missing"), 0;
cout << s[dfs(a, b)];
}
能过,但是一下不仅过不了,还MLE了
#include <bits/stdc++.h>
using namespace std;
const int maxa = 1e5 + 5, maxb = 50;
int a, b, n, f[maxa][maxb];
int dfs(int x, int y) {
if (pow(x, y) >= n) return f[x][y] = 2;
if (f[x][y]) return f[x][y];
return f[x][y] = 3 - min(dfs(x + 1, y), dfs(x, y + 1));
}
string s[3] = {"Missing", "Stas", "Masha"};
int main() {
cin >> a >> b >> n;
if (a == 1 and pow(2, b) >= n) return puts("Missing"), 0;
cout << s[dfs(a, b)];
}