#include <bits/stdc++.h>
using namespace std;
char a[3010][3010];
int f[3010][3010] , vert , oriz , n , m;
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;
if (oriz >= 26)
printf ("%d ",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 , sol = 0;
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);
}
}
}
if (sol == 26)
sol++;
fprintf (fout,"%d",sol);
return 0;
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:104: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:106: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 |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
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 |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
360 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
6 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
29 |
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 |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
360 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
6 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |