-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path81741226.cpp
56 lines (56 loc) · 1.05 KB
/
81741226.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
int arr[1000+100][1100];
void test()
{
for(int i=0;i<1100;i++)
for(int j=0;j<1100;j++)
arr[i][j]=0;
int n,m,x,y;
scanf("%d%d%d%d",&n,&m,&x,&y);
int cells=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
char c;
scanf("%c",&c);
if(c=='\n')
j--;
if(c=='.')
{
arr[i][j]=1;
cells++;
}
}
int res=0;
if(y>=2*x)
cout<<x*cells<<endl;
else
{
for(int i=1;i<=n;i++)
{
int ones=0;
for(int j=1;j<=m+1;j++)
{
if(arr[i][j]==1)
ones++;
else
{
res+=(ones/2) *y+(ones%2)*x;
ones=0;
}
}
}
cout<<res<<endl;
}
}
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
test();
}
return 0;
}