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;
#define pb push_back
const int N = (int)3e3+2;
int n, m;
string s[N];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> s[i];
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(s[i][j]!='R') continue;
bool ok1 = 0, ok2 = 0;
if(j+2<m and s[i][j+1]=='G' and s[i][j+2]=='W') ok1=1;
if(i+2<n and s[i+1][j]=='G' and s[i+2][j]=='W') ok2=1;
s[i][j] = ok2*2+ok1;
}
}
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if(s[i][j]=='G' or s[i][j]=='W') s[i][j]=0;
int ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(!s[i][j]) continue;
if(s[i][j]=='#') continue;
int choice = 0, bad = 0;
if(s[i][j]==1){
if(s[i][j+1]!='#' and s[i][j+2]!='#') choice=1;
}
else if(s[i][j]==2){
if(s[i+1][j]!='#' and s[i+2][j]!='#'){
choice=2;
if(j>=1 and (s[i+1][j-1]==1 or s[i+1][j-1]==3)) bad++;
if(j>=2 and (s[i+2][j-2]==1 or s[i+2][j-2]==3)) bad++;
}
}
else{
if(s[i][j+1]!='#' and s[i][j+2]!='#') choice=1;
else if(s[i+1][j]!='#' and s[i+2][j]!='#'){
choice=2;
if(j>=1 and (s[i+1][j-1]==1 or s[i+1][j-1]==3)) bad++;
if(j>=2 and (s[i+2][j-2]==1 or s[i+2][j-2]==3)) bad++;
}
}
if(choice==1 and bad<=1){
s[i][j]=s[i][j+1]=s[i][j+2]='#';
ans++;
}
else if(choice==2 and bad<=1){
s[i][j]=s[i+1][j]=s[i+2][j]='#';
ans++;
}
else s[i][j]=0;
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |