Submission #133973

# Submission time Handle Problem Language Result Execution time Memory
133973 2019-07-21T20:01:55 Z Lawliet Tracks in the Snow (BOI13_tracks) C++14
86.875 / 100
2000 ms 1048576 KB
#include <bits/stdc++.h>

#define MAX 4010

using namespace std;
typedef pair<int,int> pii;

int dx[] = {0 , 0 , 1 , -1};
int dy[] = {1 , -1 , 0 , 0};

int n, m;
int curNode;

int node[MAX][MAX];
int dist[MAX*MAX];

bool marc[MAX][MAX];
bool marcBFS[MAX*MAX];

pii cell[MAX*MAX];

char v[MAX][MAX];

//vector<int> dist;

//vector<bool> marcBFS;

//vector<pii> cell;

queue<int> q;

bool check(int i, int j)
{
	if(i <= 0 || j <= 0) return false;
	if(i > n || j > m) return false;

	return true;
}

void DFS(int i, int j)//ESTOU PEGANDO TODOS COM V
{
	marc[i][j] = true;

	for(int g = 0 ; g < 4 ; g++)
	{
		int ni = i + dx[g];
		int nj = j + dy[g];

		if(!check(ni , nj)) continue;

		if(marc[ni][nj]) continue;
		if(v[ni][nj] != v[i][j]) continue;

		node[ni][nj] = node[i][j];

		DFS(ni , nj);
	}
}

void DFSMake(int i, int j)
{
	marc[i][j] = true;

	for(int g = 0 ; g < 4 ; g++)
	{
		int ni = i + dx[g];
		int nj = j + dy[g];

		//printf("%d %d %d %d\n",i,j,ni,nj);

		if(!check(ni , nj)) continue;

		//printf("i = %d   %d %d %d\n",i,j,ni,nj);

		if(marc[ni][nj]) continue;

		//printf("i = %d  j = %d  ni = %d  nj = %d\n",i,j,ni,nj);

		if(v[ni][nj] == '.') continue;

		if(v[ni][nj] != v[i][j] && !marcBFS[ node[ni][nj] ])
		{
			if(!marcBFS[ node[ni][nj] ])
			{
				q.push( node[ni][nj] );

				marcBFS[ node[ni][nj] ] = true;
				dist[ node[ni][nj] ] = dist[ node[i][j] ] + 1;

			}
			//printf("i = %d  j = %d      %d %d\n",i,j,ni,nj);

			continue;
		}

		if(v[ni][nj] != v[i][j]) continue;

		DFSMake(ni , nj);
	}
}

int main()
{
	scanf("%d %d",&n,&m);

	for(int g = 1 ; g <= n ; g++)
		for(int h = 1 ; h <= m ; h++)
			scanf(" %c",&v[g][h]);

	for(int g = 1 ; g <= n ; g++)
	{
		for(int h = 1 ; h <= m ; h++)
		{
			if(marc[g][h]) continue;
			if(v[g][h] == '.') continue;

			node[g][h] = curNode++;//CURNODE N EXISTE

			//printf("g = %d  h = %d    %d\n",g,h,curNode - 1) ;

			//dist.push_back( 0 );

			cell[curNode - 1] = {g , h};
			//cell.push_back({g , h});
			//marcBFS.push_back(false);

			DFS(g , h);
		}
	}

	memset(marc , false , sizeof(marc));

	marcBFS[0] = true;
	q.push(0);

	while( !q.empty() )
	{
		int cur = q.front(); q.pop();

		int i = cell[cur].first;
		int j = cell[cur].second;

		DFSMake(i , j);
	}

	int ans = 0;

	for(int g = 0 ; g < curNode ; g++)
		ans = max(ans , dist[g]);

	printf("%d\n",ans + 1);
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:104:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
tracks.cpp:108:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c",&v[g][h]);
    ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 60 ms 21624 KB Output is correct
2 Correct 15 ms 16248 KB Output is correct
3 Correct 16 ms 16504 KB Output is correct
4 Correct 42 ms 21704 KB Output is correct
5 Correct 25 ms 18808 KB Output is correct
6 Correct 15 ms 16380 KB Output is correct
7 Correct 16 ms 16504 KB Output is correct
8 Correct 17 ms 16680 KB Output is correct
9 Correct 16 ms 16860 KB Output is correct
10 Correct 24 ms 18424 KB Output is correct
11 Correct 22 ms 18296 KB Output is correct
12 Correct 32 ms 19064 KB Output is correct
13 Correct 24 ms 18808 KB Output is correct
14 Correct 24 ms 18808 KB Output is correct
15 Correct 57 ms 21496 KB Output is correct
16 Correct 61 ms 21676 KB Output is correct
17 Correct 48 ms 21496 KB Output is correct
18 Correct 41 ms 21752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 47072 KB Output is correct
2 Correct 204 ms 33552 KB Output is correct
3 Correct 1288 ms 108300 KB Output is correct
4 Correct 355 ms 52088 KB Output is correct
5 Correct 764 ms 126820 KB Output is correct
6 Execution timed out 2052 ms 153304 KB Time limit exceeded
7 Correct 51 ms 48376 KB Output is correct
8 Correct 62 ms 46960 KB Output is correct
9 Correct 22 ms 16760 KB Output is correct
10 Correct 18 ms 16556 KB Output is correct
11 Correct 51 ms 47736 KB Output is correct
12 Correct 18 ms 17528 KB Output is correct
13 Correct 195 ms 33560 KB Output is correct
14 Correct 119 ms 27768 KB Output is correct
15 Correct 127 ms 30916 KB Output is correct
16 Correct 102 ms 22776 KB Output is correct
17 Correct 468 ms 51512 KB Output is correct
18 Correct 431 ms 58872 KB Output is correct
19 Correct 342 ms 52164 KB Output is correct
20 Correct 307 ms 45944 KB Output is correct
21 Correct 757 ms 79872 KB Output is correct
22 Correct 768 ms 126956 KB Output is correct
23 Correct 912 ms 72436 KB Output is correct
24 Correct 710 ms 85264 KB Output is correct
25 Correct 1670 ms 139896 KB Output is correct
26 Execution timed out 2164 ms 1048576 KB Time limit exceeded
27 Correct 1996 ms 330804 KB Output is correct
28 Execution timed out 2043 ms 153336 KB Time limit exceeded
29 Execution timed out 2062 ms 142632 KB Time limit exceeded
30 Execution timed out 2070 ms 222600 KB Time limit exceeded
31 Correct 1877 ms 107256 KB Output is correct
32 Execution timed out 2078 ms 450456 KB Time limit exceeded