fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define bint __int128
  7. #define _3bkarm cin.tie(NULL); cout.tie(NULL); ios::sync_with_stdio(false);
  8.  
  9. const int N = 1001;
  10.  
  11. int dp[N][N];
  12.  
  13. vector<int> have;
  14. int solve(int at, int x) {
  15. if ( at == have.size() or have[at] > x ) return x;
  16. int& ans = dp[at][x];
  17. if (~ans) return ans;
  18. return ans = min( solve(at + 1, x), solve(at + 1, x - have[at]) );
  19. }
  20.  
  21. void getShitDone() {
  22. int n, k, l;
  23. cin >> n >> k >> l;
  24.  
  25. int r = n - k - l;
  26. if (l > r) swap(l, r);
  27.  
  28. if (l == r) {
  29. if (l == k) {
  30. if (k == 1) {
  31. cout << 2;
  32. } else if (k == 2) {
  33. cout << 3;
  34. } else if (k == 3) {
  35. cout << 3;
  36. } else if (k == 4) {
  37. cout << 2;
  38. } else {
  39. cout << 0;
  40. }
  41. } else {
  42. for (int i = 1; i < r; ++i) if (i != k) have.push_back(i);
  43. memset( dp, -1, sizeof(dp) );
  44. cout << solve(0, r);
  45. }
  46. } else if (l > k or r < k) {
  47. cout << 0;
  48. } else if (l == k) {
  49. if (k <= 2) {
  50. cout << 1;
  51. } else {
  52. cout << 0;
  53. }
  54. } else if (r == k) {
  55. if (k == 1) {
  56. if (l == 0) {
  57. cout << 1;
  58. } else {
  59. cout << -1;
  60. }
  61. } else if (k == 2) {
  62. if (l == 0) {
  63. cout << 1;
  64. } else if (l == 1) {
  65. cout << 2;
  66. } else {
  67. cout << -1;
  68. }
  69. } else if (k == 3) {
  70. if (l == 0) {
  71. cout << 0;
  72. } else if (l == 1) {
  73. cout << 1;
  74. } else if (l == 2) {
  75. cout << 2;
  76. } else {
  77. cout << -1;
  78. }
  79. } else if (k == 4) {
  80. if (l == 0) {
  81. cout << 0;
  82. } else if (l == 1) {
  83. cout << 1;
  84. } else if (l == 2) {
  85. cout << 0;
  86. } else if (l == 3) {
  87. cout << 1;
  88. } else {
  89. cout << -1;
  90. }
  91. } else {
  92. cout << 0;
  93. }
  94. } else {
  95. cout << 0;
  96. }
  97. }
  98.  
  99. signed main() {
  100. _3bkarm
  101.  
  102. int ts = 1;
  103. // cin >> ts;
  104. while (ts--) {
  105. getShitDone();
  106. if (ts != 0) cout << '\n';
  107. }
  108.  
  109. return 0;
  110. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty