Submission #164157

# Submission time Handle Problem Language Result Execution time Memory
164157 2019-11-17T20:53:05 Z MohamedAhmed04 Nautilus (BOI19_nautilus) C++14
66 / 100
1000 ms 888 KB
#include <bits/stdc++.h>

using namespace std ;

const int MAX = 505 ;

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

int n , m , k ;
string s ;
char arr[MAX][MAX] ;
bitset<MAX*MAX>dp1 , dp2 ;

int encode(int x , int y)
{
	return x*m+y ;
}

pair<int , int>decode(int now)
{
	return {now/m , now%m} ;
}

void check(int x , int y)
{
	if(x < 0 || x >= n || y < 0 || y >= m)
		return ;
	if(arr[x][y] == '#')
		return ;
	dp2[encode(x , y)] = 1 ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m>>k ;
	for(int i = 0 ; i < n ; ++i)
	{
		for(int j = 0 ; j < m ; ++j)
			cin>>arr[i][j] ;
	}
	cin>>s ;
	for(int i = 0 ; i < n ; ++i)
	{
		for(int j = 0 ; j < m ; ++j)
		{
			if(arr[i][j] == '#')
				continue ;
			dp1[encode(i , j)] = 1 ;
		}
	}
	pair<int , int>p ;
	int x , y ;
	for(int i = 0 ; i < k ; ++i)
	{
		dp2.reset() ;
		for(int j = dp1._Find_first() ; j < dp1.size() ; j = dp1._Find_next(j))
		{
			p = decode(j) ;
			x = p.first , y = p.second ;
			if(s[i] == 'N')
				check(x-1 , y) ;
			else if(s[i] == 'S')
				check(x+1 , y) ;
			else if(s[i] == 'E')
				check(x , y+1) ;
			else if(s[i] == 'W')
				check(x , y-1) ;
			else
			{
				for(int ii = 0 ; ii < 4 ; ++ii)
				{
					x = p.first + dx[ii] , y = p.second + dy[ii] ;
					check(x , y) ;
				}
			}
		}
		dp1 = dp2 ;
	}
	return cout<<dp1.count()<<"\n" , 0 ;
}		

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:59:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = dp1._Find_first() ; j < dp1.size() ; j = dp1._Find_next(j))
                                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 21 ms 504 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 504 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 30 ms 376 KB Output is correct
8 Correct 9 ms 504 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 40 ms 376 KB Output is correct
13 Correct 34 ms 504 KB Output is correct
14 Correct 25 ms 504 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 72 ms 632 KB Output is correct
18 Correct 43 ms 504 KB Output is correct
19 Correct 21 ms 500 KB Output is correct
20 Correct 8 ms 508 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 504 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 30 ms 376 KB Output is correct
8 Correct 9 ms 504 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 40 ms 376 KB Output is correct
13 Correct 34 ms 504 KB Output is correct
14 Correct 25 ms 504 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 72 ms 632 KB Output is correct
18 Correct 43 ms 504 KB Output is correct
19 Correct 21 ms 500 KB Output is correct
20 Correct 8 ms 508 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Execution timed out 1054 ms 888 KB Time limit exceeded
23 Halted 0 ms 0 KB -