#include<stdio.h>
#include<vector>
#include<queue>
using namespace std;
char in[405];
bool fl[1200][1200];
int dx[4] = { -1,0,0,1 }, dy[4] = { 0,1,-1,0 }, n, m, nn, mm;
vector<int> g[1200 * 1200];
int ans[400 * 400], v[1200][1200], nf;
inline int pti(int y, int x)
{
return y*mm + x;
}
int foo(int i, int j)
{
if (v[i][j] != 0) return ans[v[i][j]];
nf++;
v[i][j] = nf;
queue<int> q;
q.emplace(pti(i, j));
while (!q.empty())
{
int idx = q.front();
int y = idx / mm;
int x = idx % mm;
q.pop();
if(ans[nf]>=0) ans[nf]++;
for (int e : g[idx])
{
int yy = e / mm, xx = e%mm;
if ((yy + n == i || i + n == yy) && (xx + m == j || j + m == xx))
{
ans[nf] = -1;
}
if (v[yy][xx]) continue;
v[yy][xx] = nf;
q.emplace(e);
}
}
return ans[nf];
}
int main()
{
scanf("%d%d", &n, &m);
nn = n * 3;
mm = m * 3;
for(int i=0;i<n;i++)
{
scanf("%s", in);
for (int j = 0; j < m; j++)
{
fl[i][j] = fl[i][j + m] = fl[i][j + 2 * m] = in[j] == 'B';
fl[i + n][j] = fl[i + n][j + m] = fl[i + n][j + 2 * m] = in[j] == 'B';
fl[i + n * 2][j] = fl[i + n * 2][j + m] = fl[i + n * 2][j + 2 * m] = in[j] == 'B';
}
}
for(int i=0;i<nn;i++)
for (int j = 0; j < mm; j++)
{
int p1 = pti(i, j);
for (int d = 0; d < 4; d++)
{
int x = j + dx[d], y = i + dy[d];
if (x < 0 || x >= 3 * m || y < 0 || y >= 3 * n) continue;
if (fl[i][j] != fl[y][x]) continue;
int p2 = pti(y, x);
g[p1].push_back(p2);
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
printf("%d ", foo(i+n, j+m));
}
puts("");
}
}
Compilation message
YZ.cpp: In function 'int foo(int, int)':
YZ.cpp:28:7: warning: unused variable 'y' [-Wunused-variable]
int y = idx / mm;
^
YZ.cpp:29:7: warning: unused variable 'x' [-Wunused-variable]
int x = idx % mm;
^
YZ.cpp: In function 'int main()':
YZ.cpp:49:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
YZ.cpp:54:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", in);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
406 ms |
88352 KB |
Output is partially correct |
2 |
Incorrect |
353 ms |
88352 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |