-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf39e.cpp
More file actions
45 lines (39 loc) · 859 Bytes
/
cf39e.cpp
File metadata and controls
45 lines (39 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
using namespace std;
long long pow(long long a, long long b, long long n) {
long long ret = 1;
for (int i = 0; i < b && ret < n; ++i) {
ret *= a;
}
return ret;
}
map<pair<long long, long long>, int> dp;
int dfs(long long a, long long b, long long n) {
if (pow(a, b, n) >= n) {
return 1;
}
if (dp.count(make_pair(a, b)) == 0) {
if (a == 1 && pow(a + 1, b, n) >= n) {
dp[make_pair(a, b)] = 0;
} else if (b == 1 && pow(a, b + 1, n) >= n) {
dp[make_pair(a, b)] = (n - a) % 2 == 0 ? 1 : -1;
} else {
dp[make_pair(a, b)] = max(-dfs(a + 1, b, n), -dfs(a, b + 1, n));
}
}
return dp[make_pair(a, b)];
}
const char* ans[] = {
"Stas",
"Missing",
"Masha",
};
int main() {
int a, b, n;
scanf("%d%d%d", &a, &b, &n);
puts(ans[dfs(a, b, n) + 1]);
return 0;
}