#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];
bool matched[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*3001+dy*3000*3002;
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+1)/2;
}
int main() {
cin >> n >> m;
F0R(i, n) {
F0R(j, m) {
matched[i][j] = false;
cin >> A[i][j];
}
}
int ans = 0;
F0R(i, n) {
F0R(j, m) {
if (A[i][j] == 'R' && !matched[i][j]) {
ans += getCt(i, j);
}
}
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |