Submission #22737

# Submission time Handle Problem Language Result Execution time Memory
22737 2017-04-30T07:08:06 Z past future present(#977, kazel, pjh0123, nemo) Young Zebra (KRIII5_YZ) C++14
Compilation error
0 ms 0 KB
#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 (v[yy][xx]) continue;
			int yc = abs(yy - i), xc = abs(xx - j);
			if(yc%n == 0 && xc%m == 0)
			{
				ans[nf] = -1;
			}
			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:36:23: error: 'abs' was not declared in this scope
    int yc = abs(yy - i), xc = abs(xx - j);
                       ^
YZ.cpp:37:20: error: 'xc' was not declared in this scope
    if(yc%n == 0 && xc%m == 0)
                    ^
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:50: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:55:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", in);
                  ^