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 ll long long
#define ii pair<int, int>
#define pA first
#define pB second
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
int getCt(int i, int j);
int n, m;
char A[3000][3000];
string match = "RGW";
bool valid(int i, int j, int dx, int dy) {
int startMult = A[i][j] == 'R' ? 0 : (A[i][j] == 'G' ? 1 : 2);
int ct = 0;
FOR(x, i-dx*startMult, i+dx*(2-startMult)+1) {
FOR(y, j-dy*startMult, j+dy*(2-startMult)+1) {
if (x<0||x>=n||y<0||y>=m) return false;
if (A[x][y] != match[ct++]) return false;
}
}
return true;
}
set<int> seen;
int process(int i, int j, int dx, int dy) {
int startMult = A[i][j] == 'R' ? 0 : (A[i][j] == 'G' ? 1 : 2);
int ans = 1;
int ct = 0;
FOR(x, i-dx*startMult, i+dx*(2-startMult)+1) {
FOR(y, j-dy*startMult, j+dy*(2-startMult)+1) {
if (ct==0) {
int num = x*3000+y+dx*3000*3000*1+dy*3000*3000*2;
if (seen.count(num)) return 0;
seen.insert(num);
ct++;
}
ans += getCt(x, y);
}
}
return ans;
}
int getCt(int i, int j) {
int ct = 0;
if (valid(i, j, 0, 1)) {
ct += process(i, j, 0, 1);
}
if (valid(i, j, 1, 0)) {
ct += process(i, j, 1, 0);
}
return ct;
}
int main() {
cin >> n >> m;
F0R(i, n) {
F0R(j, m) {
cin >> A[i][j];
}
}
int ans = 0;
F0R(i, n) {
F0R(j, m) {
ans += (getCt(i, j)+1)/2;
}
}
cout << ans << endl;
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... |