fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define F first
  4. #define S second
  5. int t , n , k , dp[55][55] , vist[55][55] , vid;
  6. int rec(int l , int r)
  7. {
  8. if (r-l+1 < k)return 0;
  9. if (vist[l][r] == vid)return dp[l][r];
  10. vist[l][r] = vid;
  11. int en = l , st = l;
  12. for (int j = 1 ; j < k ; ++j)
  13. en++;
  14. set<int>se;
  15. while(en <= r)
  16. {
  17. se.insert(rec(l , st-1) ^ rec(en+1 , r));
  18. st++ , en++;
  19. }
  20. int cou = 0;
  21. for (auto x : se)
  22. {
  23. if (x != cou)break;
  24. cou++;
  25. }
  26. return dp[l][r] = cou;
  27. }
  28. int main()
  29. {
  30. ios::sync_with_stdio(0);
  31. cin.tie(0);
  32. cin >> t;
  33. for (int tt = 1 ; tt <= t ; ++tt)
  34. {
  35. cin >> n >> k;
  36. vid++;
  37. if (rec(1 , n))
  38. cout << "Case " << tt << ": " << "Winning" << '\n';
  39. else
  40. cout << "Case " << tt << ": " << "Losing" << '\n';
  41. }
  42.  
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.01s 5380KB
stdin
Standard input is empty
stdout
Standard output is empty