Advertisement
xT30x

Untitled

Jan 29th, 2023
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define prm(x) x.begin(), x.end()
  4. #define srt(x) sort(prm(x))
  5. #define rvs(x) reverse(prm(x))
  6.  
  7. using namespace std;
  8. using ll = long long;
  9. using ld = long double;
  10.  
  11. int main()
  12. {
  13.     // ifstream cin("eq4.in");
  14.     // ofstream cout("eq4.out");
  15.     ll c;
  16.     cin >> c;
  17.     cin.ignore();
  18.     string x;
  19.     getline(cin, x);
  20.     ll l, r, v;
  21.     cin >> l >> r >> v;
  22.     map<char, ll> z1;
  23.     for (int i = 0; i < x.size();)
  24.     {
  25.         ll a, b = 0;
  26.         char ct = 'w';
  27.         if (x.at(i) == '+')
  28.         {
  29.             a = 1;
  30.         }
  31.         else
  32.         {
  33.             a = -1;
  34.         }
  35.         i++;
  36.         while (i < x.size() && isdigit(x.at(i)))
  37.         {
  38.             b = b * 10 + (x.at(i) - '0');
  39.             i++;
  40.         }
  41.         if (i < x.size() && isalpha(x.at(i)))
  42.         {
  43.             ct = x.at(i);
  44.             i++;
  45.         }
  46.         if (b == 0)
  47.         {
  48.             b = 1;
  49.         }
  50.         z1[ct] += a * b;
  51.     }
  52.     if (c == 1)
  53.     {
  54.  
  55.         cout << z1['x'] + z1['y'] + z1['z'] + z1['t'] + z1['w'] << endl;
  56.     }
  57.     else
  58.     {
  59.         ll ans = 0;
  60.         ll hp = z1['w'];
  61.         map<ll, ll> v1;
  62.         for (int i = l; i < r; i++)
  63.         {
  64.             for (int j = l; j < r; j++)
  65.             {
  66.                 v1[hp + z1['x'] * i + z1['y'] * j] += 1;
  67.             }
  68.         }
  69.         for (int i = l; i < r; i++)
  70.         {
  71.             for (int j = l; j < r; j++)
  72.             {
  73.                 ll val = v - (z1['z'] * i + z1['t'] * j);
  74.                 if (v1.find(val) != v1.end())
  75.                 {
  76.                     ans += v1[val];
  77.                 }
  78.             }
  79.         }
  80.         cout << ans << endl;
  81.     }
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement