Advertisement
_rashed

UVA 28187075

Jan 25th, 2023
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. /*
  6. Ordered set usage:
  7. order_of_key (k) : Number of items strictly smaller than k.
  8. find_by_order(k) : K-th element in a set (counting from zero).
  9. */
  10.  
  11. #include <ext/pb_ds/assoc_container.hpp>
  12. #include <ext/pb_ds/tree_policy.hpp>
  13. using namespace __gnu_pbds;
  14. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  15.  
  16. const int OO = 1e9;
  17. const double EPS = 1e-9;
  18.  
  19. int mem[1000001][2],n,m,moves[10];
  20. int solve(int rem, int turn) {
  21.     if(rem == 0) {
  22.         return !turn;
  23.     }
  24.     if(mem[rem][turn] != -1) {
  25.         return mem[rem][turn];
  26.     }
  27.     int &ret = mem[rem][turn];
  28.     ret = !turn;
  29.     for(int i = 0; i < m; i++) {
  30.         if(moves[i] <= rem) {
  31.             int curr = solve(rem-moves[i],!turn);
  32.             if(curr == turn) {
  33.                 ret = turn;
  34.                 break;
  35.             }
  36.         }
  37.     }
  38.     return ret;
  39. }
  40.  
  41. int main()
  42. {
  43.     ios_base::sync_with_stdio(NULL);
  44.     cin.tie(0);
  45.     while(cin >> n >> m) {
  46.         for(int i = 0; i < m; i++) {
  47.             cin >> moves[i];
  48.         }
  49.         for(int i = 0; i <= n; i++) {
  50.             mem[i][0] = mem[i][1] = -1;
  51.         }
  52.         for(int i = 1; i <= n; i++) {
  53.             solve(i,0);
  54.             solve(i,1);
  55.         }
  56.         int winner = solve(n,0);
  57.         cout << (winner ? "Ollie wins\n":"Stan wins\n");
  58.     }
  59.     return 0;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement