Submission #72030

# Submission time Handle Problem Language Result Execution time Memory
72030 2018-08-26T04:50:28 Z Semteo For Ajou(#2257, tph00300, txepahs, bmw) Aquatic Labyrinth (FXCUP3_aqua) C++14
0 / 100
3 ms 488 KB
#include <stdio.h>
#include <algorithm>
using namespace std;
int map[901][901];
int x[5] = { 0,-1,0,1,0 }, y[5] = { 0,0,1,0,-1 };
int tx, ty, f, s, px[10000001], py[10000001];
char arr[10001];
int main()
{
	int n,i,j,k,ex,ey;

	scanf("%d", &n);

	f = 1;
	s = 1;
	for (i = 1; i <= n; i++)
	{
		scanf("%s", arr);
		for (j = 0; j < n; j++)
		{
			if (arr[j] == 'M')
			{
				map[i][j + 1] = 0;
				px[f] = i;
				py[f] = j + 1;
			}
			else if (arr[j] == 'W')
				map[i][j + 1] = -1;
			else if (arr[j] == '.')
				map[i][j + 1] = 0;
			else if (arr[j] == 'H')
			{
				map[i][j + 1] = 0;
				ex = i;
				ey = j+1;
			}
		}
	}

	map[px[f]][py[f]] = 1;
	int flag,a=0;
	while (f <= s)
	{
		for (i = 1; i <= 4; i++)
		{
			flag = 0;
			a = 0;
			tx = px[f];
			ty = py[f];
			while (flag != 2)
			{
				tx += x[i];
				ty += y[i];
				if (tx<0 || ty<0 || tx>n || ty>n)
					break;
				if (map[tx][ty] == -1)
				{
					flag = 1;
					a++;
				}
				if (map[tx][ty] != -1 && flag == 1)
				{
					flag = 2;
					break;
				}
			}
			if (flag == 2)
			{
				if (map[tx][ty] == 0 || map[tx][ty] > a*a + map[px[f]][py[f]])
				{
					map[tx][ty] = a * a + map[px[f]][py[f]];
					s++;
					px[s] = tx;
					py[s] = ty;
				}
			}
		}
		f++;
	}
	if (map[ex][ey] == 0)
		printf("%d", -1);
	else
		printf("%d", map[ex][ey]-1);
	return 0;
}

Compilation message

aqua.cpp: In function 'int main()':
aqua.cpp:10:12: warning: unused variable 'k' [-Wunused-variable]
  int n,i,j,k,ex,ey;
            ^
aqua.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
aqua.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", arr);
   ~~~~~^~~~~~~~~~~
aqua.cpp:80:16: warning: 'ey' may be used uninitialized in this function [-Wmaybe-uninitialized]
  if (map[ex][ey] == 0)
      ~~~~~~~~~~^
aqua.cpp:80:16: warning: 'ex' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 3 ms 380 KB Output is correct
2 Incorrect 2 ms 488 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 380 KB Output is correct
2 Incorrect 2 ms 488 KB Output isn't correct
3 Halted 0 ms 0 KB -