Dang_Quan_10_Tin

CAU1 HSGHN L9 2014-2015

Dec 25th, 2021 (edited)
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #define task "CAU1"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int a, b, c;
  10.  
  11. void Read()
  12. {
  13.     cin >> a >> b >> c;
  14.  
  15.     if (a < b)
  16.         swap(a, b);
  17. }
  18.  
  19. // a >= sqrt(c)
  20. void Subtask_1()
  21. {
  22.     int ans(0);
  23.  
  24.     for (int x = 1; 1ll * x * a < c; ++x)
  25.         if ((c - x * a) % b == 0) // Tồn tại y thỏa mãn
  26.             ++ans;
  27.  
  28.     cout << ans;
  29. }
  30.  
  31. #define bit(i, c) (((c) >> (i)) & 1) // c_i
  32.  
  33. void Subtask_2()
  34. {
  35.     vector<vector<int>> f(__lg(c) + 3, vector<int>(a * __lg(c) + 3, 0));
  36.  
  37.     for (int i = 0; (1 << i) <= c; ++i)
  38.         for (int j = 0; j <= i * a; ++j)
  39.         {
  40.             if (i == 0 && j == 0)
  41.                 ++f[i][j];
  42.  
  43.             if (j % 2 == bit(i, c))
  44.                 f[i + 1][j / 2] += f[i][j];
  45.             if ((j + a) % 2 == bit(i, c))
  46.                 f[i + 1][(j + a) / 2] += f[i][j];
  47.             if ((j + b) % 2 == bit(i, c))
  48.                 f[i + 1][(j + b) / 2] += f[i][j];
  49.             if ((j + a + b) % 2 == bit(i, c))
  50.                 f[i + 1][(j + a + b) / 2] += f[i][j];
  51.         }
  52.  
  53.     cout << f[__lg(c) + 1][0] - (c % b == 0) - (c % a == 0);
  54. }
  55.  
  56. int32_t main()
  57. {
  58.     ios::sync_with_stdio(0);
  59.     cin.tie(0);
  60.     cout.tie(0);
  61.     if (fopen(task ".INP", "r"))
  62.     {
  63.         freopen(task ".INP", "r", stdin);
  64.         freopen(task ".OUT", "w", stdout);
  65.     }
  66.  
  67.     Read();
  68.  
  69.     if (1ll * a * a >= c)
  70.         Subtask_1();
  71.     else
  72.         Subtask_2();
  73. }
  74.  
Add Comment
Please, Sign In to add comment