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>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int n, m;
int a[3009][3009];
int cl(int x, int y){
return(x >= 0 && y >= 0 && a[x][y] == 1 && a[x][y+1] == 2 && a[x][y+2] == 3);
}
int cd(int x, int y){
return(x >= 0 && y >= 0 && a[x][y] == 1 && a[x+1][y] == 2 && a[x+2][y] == 3);
}
int ans = 0;
void fl(int x, int y){
if(!cl(x, y)) return;
++ans;
a[x][y] = a[x][y+1] = a[x][y+2] = 0;
}
void fd(int x, int y){
if(!cd(x, y)) return;
++ans;
a[x][y] = a[x+1][y] = a[x+2][y] = 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n >> m;
string s;
for(int i = 0; i < n; ++i){
cin >> s;
for(int j = 0; j < m; ++j){
if(s[j] == 'R')
a[i][j] = 1;
else if(s[j] == 'G')
a[i][j] = 2;
else
a[i][j] = 3;
}
}
for(int i = 0; i < n; ++i)
for(int j = 0; j < m; ++j){
if(a[i][j] != 1) continue;
int val1 = 0;
int val2 = 0;
vector<pii> v;
for(int red = 0; red <= i && red <= j; ++red){
if(a[i-red][j-red] != 1) break;
v.pb({(i-red), (j-red)});
val1 += cl((i-red), (j-red));
val2 += cd((i-red), (j-red));
}
for(auto u : v){
if(val1 > val2)
fl(u.ff, u.ss);
else
fd(u.ff, u.ss);
a[u.ff][u.ss] = 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... |