Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <bits/stdc++.h>
- using namespace std;
- /*
- Ordered set usage:
- order_of_key (k) : Number of items strictly smaller than k.
- find_by_order(k) : K-th element in a set (counting from zero).
- */
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace __gnu_pbds;
- #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
- const int OO = 1e9;
- const double EPS = 1e-9;
- int mem[1000001][2],n,m,moves[10];
- int solve(int rem, int turn) {
- if(rem == 0) {
- return !turn;
- }
- if(mem[rem][turn] != -1) {
- return mem[rem][turn];
- }
- int &ret = mem[rem][turn];
- ret = !turn;
- for(int i = 0; i < m; i++) {
- if(moves[i] <= rem) {
- int curr = solve(rem-moves[i],!turn);
- if(curr == turn) {
- ret = turn;
- break;
- }
- }
- }
- return ret;
- }
- int main()
- {
- ios_base::sync_with_stdio(NULL);
- cin.tie(0);
- while(cin >> n >> m) {
- for(int i = 0; i < m; i++) {
- cin >> moves[i];
- }
- for(int i = 0; i <= n; i++) {
- mem[i][0] = mem[i][1] = -1;
- }
- for(int i = 1; i <= n; i++) {
- solve(i,0);
- solve(i,1);
- }
- int winner = solve(n,0);
- cout << (winner ? "Ollie wins\n":"Stan wins\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement