This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin>>n>>m;
vector<string> graph(n);
vector<vector<bool>> visited(n,vector<bool>(m));
for (int i=0;i<n;i++){
cin>>graph[i];
}
long long res=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(j>0&&j<m-1&&graph[i][j]=='G'&&graph[i][j-1]=='R'&&graph[i][j+1]=='W'&&!visited[i][j-1]&&!visited[i][j]&&!visited[i][j+1]) {
res++;
visited[i][j]=true;
visited[i][j-1]=true;
visited[i][j+1]=true;
} else if (i>0&&i<n-1&&graph[i][j]=='G'&&graph[i-1][j]=='R'&&graph[i+1][j]=='W'&&!visited[i-1][j]&&!visited[i][j]&&!visited[i+1][j]){
res++;
visited[i][j]=true;
visited[i-1][j]=true;
visited[i+1][j]=true;
}
}
}
cout<<res<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |