IMohammedNasr

D. Playing With Colors

Sep 24th, 2022
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define cin(v) for (auto &i : v) cin >> i;
  4. #define cout(v) for (auto &i : v) cout << i << " "; cout<<'\n';
  5. #define ll long long
  6. #define ull unsigned long long
  7. #define all(v) v.begin(), v.end()
  8. #define rall(v) v.rbegin(), v.rend()
  9. #define MOD 107
  10. #define endl '\n'
  11. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs"<< "\n";
  12.  
  13. void Warding()
  14. {
  15.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  16. #ifndef ONLINE_JUDGE
  17.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  18. #endif
  19. }
  20.  
  21. /*
  22. STOP USING int
  23. */
  24.  
  25.  
  26. void solve(){
  27.     string s; cin>>s;
  28.     int a, b; cin>>a>>b;
  29.     int n = s.size();
  30.     int one = count(all(s),'1'), zero = n - one;
  31.     ll cost1 = (one - count(s.begin(), s.begin() + one,'1'))*a;
  32.     ll cost2 = (one - count(s.begin() + (n-one), s.end(),'1'))*a;
  33.     ll cost3 = (zero - count(s.begin(), s.begin() + zero,'0'))*b;
  34.     ll cost4 = (zero - count(s.begin() + (n-zero), s.end(),'0'))*b;
  35.     cout<<min(cost1 + cost4, cost2 + cost3)<<endl;
  36. }
  37.  
  38.  
  39. int main()
  40. {
  41.     Warding();
  42.     int TC = 1;
  43.     // cin >> TC;
  44.     while (TC--)
  45.     {
  46.         solve();
  47.     }
  48.     Time
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment