Advertisement
jeff69

Untitled

Apr 15th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <fstream>
  5. #include <cstring>
  6. #include <string>
  7. #include <functional>
  8. #include <cmath>
  9. #include<algorithm>
  10. typedef long long ll;
  11. using namespace std;
  12. int a[55], n, l, k;
  13. int dp[1000004][2];
  14. // 2 3 12
  15. int x;
  16. int solve(int y){
  17. if (y < 0){
  18.  
  19. return x;
  20.  
  21. }
  22. if (y == 0){
  23. return 1 - x;
  24.  
  25.  
  26. }
  27. if (dp[y][x] != -1)return dp[y][x];
  28. int ans = 1 - x;
  29. int a, b, c;
  30. x = 1 - x;
  31. c = solve(y - k);
  32. x = 1 - x;
  33. x = 1 - x;
  34. b = solve(y - l);
  35. x = 1 - x;
  36. x = 1 - x;
  37.  
  38. a = solve(y - 1);
  39. x = 1 - x;
  40. //cout << a << ' ' << b << ' ' << c << '\n';
  41. if (a == x){
  42. ans = a;
  43. }
  44. else if (b == x){
  45. ans = b;
  46. }
  47. else{
  48. ans = c;
  49.  
  50. }
  51. dp[y][x] = ans;
  52. return ans;
  53. }
  54.  
  55. int main()
  56. {
  57. cin >> k >> l;
  58. if (k > l){
  59. swap(k, l);
  60. }
  61. cin >> n;
  62. memset(dp, -1, sizeof dp);
  63. for (int i = 0; i < n; i++)
  64. {
  65. cin >> a[i];
  66.  
  67. x = 0;
  68. if (solve(a[i]))cout << 'B';
  69. else cout << 'A';
  70.  
  71. }
  72.  
  73.  
  74.  
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement