Repository navigation
Expand file tree
/
Copy pathcake.cpp
More file actions
62 lines (61 loc) · 1.46 KB
/
Copy pathcake.cpp
File metadata and controls
62 lines (61 loc) · 1.46 KB
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define fastread ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
vector<ll> vec;
set<ll> s;
int main()
{
ll t;
cin>>t;
while(t--)
{
int m,n;
cin>>m>>n;
string matrix[m];
for(int i=0;i<m;i++)
cin>>matrix[i];
ll cost=0;
for(int i=0;i<m-1;i++)
{
for(int j=0;j<n-1;j++)
{
if(matrix[i][j]=='R' && matrix[i][j+1]=='R')
{
if(matrix[i+1][j]=='R')
{
matrix[i][j]='G';
cost+=5;
}
else
{
matrix[i][j+1]='G';
cost+=3;
j++;
}
}
else if(matrix[i][j]=='G' && matrix[i][j+1]=='G')
{
if(matrix[i+1][j]=='R')
{
matrix[i][j+1]='R';
cost+=3;
j++;
}
else
{
matrix[i][j]='R';
cost+=5;
}
}
else
continue;
}
cout<<matrix[i]<<" ";
}
cout<<cost<<"\n";
}
return 0;
}