fork download
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. int fbu(int n,int k,int l){
  5. vector<int> dp(1000001,-1);
  6. dp[1] = 1;
  7. dp[k] = 1;
  8. dp[l] = 1;
  9. // 1 --> winning state 0 --> loosing state
  10. for(int i=2; i<=n; i++)
  11. {
  12. if(dp[i-1]==0)
  13. {
  14. // loosing state means ith coin player will win the game
  15. dp[i] = 1;
  16. }
  17. if(2 <= i)
  18. {
  19. if(dp[i-2]==0)
  20. {
  21. dp[i] = 1;
  22. }
  23. }
  24. if(3 <= i)
  25. {
  26. if(dp[i-3]==0)
  27. {
  28. dp[i] = 1;
  29. }
  30. }
  31. // if stills person not wins then it means ith state is loosing state
  32. if(dp[i]!=1)
  33. dp[i]=0;
  34. }
  35. return dp[n];
  36. }
  37. int main()
  38. {
  39. int k,l,m;
  40. cin>>k>>l>>m;
  41. vector<int> coins(m,0);
  42. for(int i=0;i<m;i++){
  43. cin>>coins[i];
  44. }
  45. string str;
  46. for(int i=0;i<m;i++){
  47. int x = fbu(coins[i],k,l);
  48. if(x==1){
  49. str+='A';
  50. }
  51. else{
  52. str+='B';
  53. }
  54. }
  55. cout<<str;
  56. }
  57.  
Success #stdin #stdout 0.01s 7432KB
stdin
2 3 5 
3 12 113 25714 88888
stdout
ABAAB