Saleh127

codeforces 1359B.cpp

May 28th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define pi acos(-1)
  6. int main()
  7. {
  8. int r,c,a,d,e1,f2,i,j,k,l,l1;
  9. char x[10000];
  10. test
  11. {
  12. e1=0;
  13. f2=0;
  14. cin>>r>>c>>a>>d;
  15. while(r--)
  16. {
  17. cin>>x;
  18. for(j=0;j<c;j++)
  19. {
  20. if(x[j]=='.' && x[j+1]=='.')
  21. {
  22. f2++;
  23. j++;
  24. }
  25. else if(x[j]=='.') e1++;
  26. }
  27. }
  28. if(r==1 && c==1) cout<<a<<endl;
  29. else if(r==2 && c==1) cout<<2*a<<endl;
  30. else if(r==1 && c==2)
  31. {
  32. cout<<min(a,d)<<endl;
  33. }
  34. else
  35. {
  36. k=f2*d + e1*a;
  37. l=(f2*2)+e1;
  38. l1=l*a;
  39. cout<<min(k,l1)<<endl;
  40. }
  41. }
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment