-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGIT01.cpp
68 lines (64 loc) · 1.64 KB
/
GIT01.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
57
58
59
60
61
62
63
64
65
66
67
68
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t=0; cin>>t;
while(t--)
{
int N=0, M=0;
cin>>N>>M;
char ary[N][M];
for(int i=0; i<N; i++)
for(int j=0; j<M; j++)
cin>>ary[i][j];
int cost1=0, cost2=0;
for(int i=0; i<N; i++)
{
for(int j=0; j<M; j+=2)
{
if(i%2 == 0)
{
if(ary[i][j]!= 'R')
cost1+=3;
if(ary[i][j+1]!= 'G' && j+1 != M)
cost1+=5;
}
else
{
if(ary[i][j]!= 'G')
cost1+=5;
if(ary[i][j+1]!= 'R' && j+1 != M)
cost1+=3;
}
}
}
for(int i=0; i<N; i++)
{
for(int j=0; j<M; j+=2)
{
if(i%2!= 0)
{
if(ary[i][j]!= 'R')
cost2+=3;
if(ary[i][j+1]!= 'G' && j+1 != M)
cost2+=5;
}
else
{
if(ary[i][j]!= 'G')
cost2+=5;
if(ary[i][j+1]!= 'R' && j+1 != M)
cost2+=3;
}
}
}
int min;
//cout<<cost1<<" "<<cost2<<endl;
if(cost1<=cost2)
min=cost1;
else
min=cost2;
cout<<min<<endl;
}
return 0;
}