#include <bits/stdc++.h>
using namespace std;
char a[3010][3010];
int f[3010][3010] , vert , oriz , n , m , sol;
void fill (int i , int j){
f[i][j] = 1;
if (a[i][j] == 'R'){
if (a[i][j + 1] == 'G' && a[i][j + 2] == 'W' && !f[i][j + 1] && !f[i][j + 2]){
oriz++;
fill (i , j + 1);
fill (i , j + 2);
}
if (a[i + 1][j] == 'G' && a[i + 2][j] == 'W' && !f[i + 1][j] && !f[i + 2][j]){
vert++;
fill (i + 1 , j);
fill (i + 2 , j);
}
}
else if (a[i][j] == 'G'){
if (a[i][j - 1] == 'R' && a[i][j + 1] == 'W' && !f[i][j + 1] && !f[i][j - 1]){
oriz++;
fill (i , j - 1);
fill (i , j + 1);
}
if (a[i - 1][j] == 'R' && a[i + 1][j] == 'W' && !f[i - 1][j] && !f[i + 1][j]){
vert++;
fill (i + 1 , j);
fill (i - 1 , j);
}
}
else {
if (a[i][j - 1] == 'G' && a[i][j - 2] == 'R' && !f[i][j - 1] && !f[i][j - 2]){
oriz++;
fill (i , j - 1);
fill (i , j - 2);
}
if (a[i - 1][j] == 'G' && a[i - 2][j] == 'R' && !f[i - 1][j] && !f[i - 2][j]){
vert++;
fill (i - 1 , j);
fill (i - 2 , j);
}
}
}
void back (int pi , int pj){
int i , j;
sol = max(sol , oriz);
for (i = pi ; i <= n ; i++){
for (i == pi ? j = pj : j = 1; j <= m ; j++){
if (a[i][j] == 'R' && a[i][j + 1] == 'G' && a[i][j + 2] == 'W' && !f[i][j + 1] && !f[i][j + 2] && !f[i][j]){
f[i][j + 1] = f[i][j + 2] = f[i][j] = 1;
oriz++;
back(i , j + 1);
oriz--;
f[i][j + 1] = f[i][j + 2] = f[i][j] = 0;
}
else if (a[i][j] == 'R' && a[i + 1][j] == 'G' && a[i + 2][j] == 'W' && !f[i + 1][j] && !f[i + 2][j] && !f[i][j]){
f[i + 1][j] = f[i + 2][j] = f[i][j] = 1;
oriz++;
back(i + 1 , j);
oriz--;
f[i + 1][j] = f[i + 2][j] = f[i][j] = 0;
}
}
}
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int i , j;
fscanf (fin,"%d%d\n",&n,&m);
for (i = 1 ; i <= n ; i++)
fgets(a[i] + 1 , m + 10 , fin);
back(1 , 1);
/*for (i = 1 ; i <= n ; i++){
for (j = 1 ; j <= m ; j++){
if (!f[i][j] && a[i][j] == 'R'){
vert = oriz = 0;
fill (i , j);
//printf ("%d %d\n" , vert , oriz);
sol = sol + max(vert , oriz);
}
}
}*/
fprintf (fout,"%d",sol);
return 0;
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:102:13: warning: unused variable 'j' [-Wunused-variable]
int i , j;
^
dango_maker.cpp:103:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%d%d\n",&n,&m);
~~~~~~~^~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:105:14: warning: ignoring return value of 'char* fgets(char*, int, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
fgets(a[i] + 1 , m + 10 , fin);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |