Advertisement
Ali-ElMasry

Untitled

Mar 12th, 2020
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<ll, ll> pll;
  7. typedef pair<int, int> pii;
  8.  
  9. #define endl "\n"
  10.  
  11. const ll INF = 1e15;
  12. const int MOD = 1e9 + 7;
  13. const double EPS = 1e-9;
  14. const double PI = acos(-1.0);
  15.  
  16. mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());
  17.  
  18. vector<ll> read(const string& s) {
  19.     vector<ll> ret;
  20.  
  21.     ll cur;
  22.     stringstream ss(s);
  23.     while (ss >> cur)
  24.         ret.push_back(cur);
  25.  
  26.     return ret;
  27. }
  28.  
  29. int main() {
  30.     ios::sync_with_stdio(false);
  31.     cin.tie(NULL), cout.tie(NULL);
  32.  
  33.     string s;
  34.     while (getline(cin, s)) {
  35.         vector<ll> c = read(s);
  36.  
  37.         reverse(c.begin(), c.end());
  38.  
  39.         getline(cin, s);
  40.  
  41.         vector<ll> x = read(s);
  42.  
  43.         ll sum = 0;
  44.         for (auto w : c)
  45.             sum += w;
  46.  
  47.         int n = (int) x.size();
  48.         for (int i = 0; i < n; ++i) {
  49.             ll cur_x = x[i];
  50.             if (cur_x == 1)
  51.                 cout << sum << " \n"[i == n - 1];
  52.             else {
  53.                 ll ans = 0, p = 1;
  54.                 for (auto w : c) {
  55.                     ans += w * p;
  56.                     p *= cur_x;
  57.                 }
  58.                 cout << ans << " \n"[i == n - 1];
  59.             }
  60.         }
  61.     }
  62.    
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement