Advertisement
Josif_tepe

Untitled

Mar 9th, 2023
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. //   ifstream cin("input.txt");
  9.     long long n,x,y;
  10.     cin>>n>>x>>y;
  11.     string p;
  12.     cin>>p;
  13.     string s="";
  14.     for(long long i=0;i<n;i++)
  15.     {
  16.         s+=p[i];
  17.         long long j=i;
  18.         while(j<n && p[j]==p[i])
  19.         {
  20.             j++;
  21.         }
  22.         i=j-1;
  23.     }
  24.    
  25.     n=s.size();
  26.     if(n == 1 and s[0] == '1') {
  27.         return 0 * printf("0");
  28.     }
  29.     long long ans=0;
  30.     if(y<=x)
  31.     {
  32.        for(long long i=0;i<n;i++)
  33.        {
  34.            if(s[i]=='0')
  35.            {
  36.                ans+=y;
  37.            }
  38.        }
  39.     }
  40.     else if(x<y)
  41.     {
  42.         if(s.size()>=1)
  43.         {
  44.             ans+=y;
  45.             for(long long i=1;i<s.size()-1;i++)
  46.             {
  47.                 if(s[i]=='1')
  48.                 {
  49.                     ans+=x;
  50.                 }
  51.             }
  52.         }
  53.     }
  54.     cout<<ans<<endl;
  55.     return 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement