Submission #363132

# Submission time Handle Problem Language Result Execution time Memory
363132 2021-02-05T06:36:42 Z aujasvit_datta Nautilus (BOI19_nautilus) C++14
66 / 100
16 ms 10348 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int> 
#define fr first
#define sc second
#define all(a) a.begin(),a.end()
int r,c,m;
string s;
string grid[102];


void count2() {
	int dp[s.size() + 10][r + 10][c + 10];
	//dp[i][j][k]
	// whether is this position possible with the remaining string[i till end] 
	//check whether dp[]
	//
	//
	int ans = 0;
	//
	//

	for(int i = 0; i <= s.size() + 5; i++) {
		for(int j = 0; j <= r + 5; j++) {
			for(int k = 0; k <= c + 5; k++) {
				dp[i][j][k] = false;
			}
		}
	}

	for(int i = 1; i <= r; i++) {
	for(int j = 0; j < c; j++) {
		if(grid[i][j] == '#') {
			dp[0][i][j] = false;
			continue;
		}
	if(s[0] == 'N') {
		if(i != r and grid[i + 1][j] != '#') {
			dp[0][i][j] = 1;
		}
	} else if(s[0] == 'S') {
		if(i != 1 and grid[i - 1][j] != '#') {
			dp[0][i][j] = 1;
		}
	} else if(s[0] == 'W') {
		if(j != c - 1 and grid[i][j + 1] != '#') {
			dp[0][i][j] = 1;
		}

	} else if(s[0] == 'E') {
		if(j != 0 and grid[i][j - 1] != '#') {
			dp[0][i][j] = 1;
		}
	} else {
		
		if(j != 0 and grid[i][j - 1] != '#') {
			dp[0][i][j] = 1;
		}
		if(j != c - 1 and grid[i][j + 1] != '#') {
			dp[0][i][j] = 1;
		}
		if(i != 1 and grid[i - 1][j] != '#') {
			dp[0][i][j] = 1;
		}
		if(i != r and grid[i + 1][j] != '#') {
			dp[0][i][j] = 1;
		}

	}		
	}
}


	for(int i  = 1; i < s.size(); i++) {
		for(int row = 1; row <= r; row++) {
			for(int col = 0; col < c; col++) {
				//can you reach row col using first i - 1 commands
    if(dp[i - 1][row][col]) {
	    if(s[i] == 'N') {
		    if(row != 1 and grid[row - 1][col] != '#') {
			    dp[i][row - 1][col] = 1;
		} 
	} else if(s[i] == 'S') {
		if(row != r and grid[row + 1][col] != '#') {
			dp[i][row + 1][col] = 1;
		} 
	} else if(s[i] == 'W') {
		if(col != 0 and grid[row][col - 1] != '#') {
			dp[i][row][col - 1] = 1;
		} 
	} else if(s[i] == 'E') {
		if(col != c - 1 and grid[row][ col + 1] != '#') {
			dp[i][row][col + 1] = 1;
		}

	} else {
		if(row != 1 and grid[row - 1][col] != '#') {
			dp[i][row - 1][col] = 1;
		} 
		if(row != r and grid[row + 1][col] != '#') {
			dp[i][row + 1][col] = 1;
		}
		if(col != 0 and grid[row][col - 1] != '#') {
			dp[i][row][col - 1] = 1;
		}
		if(col != c - 1 and grid[row][ col + 1] != '#') {
			dp[i][row][col + 1] = 1;
		}

	}
}
			}
		}
	}


	for(int i = 1; i <= r; i++) {
		for(int j = 0; j < c; j++) {
		    if(dp[s.size() - 1][i][j] == 1) ans++;
		//	cout << dp[s.size() - 1][i][j] << " ";
		}
		
	}
	cout << ans << endl;

}



signed main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin >> r >> c >> m;
	for(int i = 1; i <= r; i++) {
		cin >> grid[i] ;
	}
	cin >> s;

	count2();
	return 0;
}

Compilation message

nautilus.cpp: In function 'void count2()':
nautilus.cpp:26:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int i = 0; i <= s.size() + 5; i++) {
      |                 ~~^~~~~~~~~~~~~~~
nautilus.cpp:77:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |  for(int i  = 1; i < s.size(); i++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 10348 KB Output is correct
2 Correct 8 ms 10348 KB Output is correct
3 Correct 7 ms 10348 KB Output is correct
4 Correct 8 ms 10348 KB Output is correct
5 Correct 8 ms 10348 KB Output is correct
6 Correct 7 ms 10348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 10348 KB Output is correct
2 Correct 8 ms 10348 KB Output is correct
3 Correct 7 ms 10348 KB Output is correct
4 Correct 8 ms 10348 KB Output is correct
5 Correct 8 ms 10348 KB Output is correct
6 Correct 7 ms 10348 KB Output is correct
7 Correct 9 ms 10348 KB Output is correct
8 Correct 10 ms 10348 KB Output is correct
9 Correct 8 ms 10348 KB Output is correct
10 Correct 8 ms 10348 KB Output is correct
11 Correct 8 ms 10348 KB Output is correct
12 Correct 10 ms 10348 KB Output is correct
13 Correct 15 ms 10348 KB Output is correct
14 Correct 16 ms 10348 KB Output is correct
15 Correct 8 ms 10348 KB Output is correct
16 Correct 7 ms 10348 KB Output is correct
17 Correct 12 ms 10348 KB Output is correct
18 Correct 15 ms 10348 KB Output is correct
19 Correct 13 ms 10348 KB Output is correct
20 Correct 9 ms 10348 KB Output is correct
21 Correct 7 ms 10348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 10348 KB Output is correct
2 Correct 8 ms 10348 KB Output is correct
3 Correct 7 ms 10348 KB Output is correct
4 Correct 8 ms 10348 KB Output is correct
5 Correct 8 ms 10348 KB Output is correct
6 Correct 7 ms 10348 KB Output is correct
7 Correct 9 ms 10348 KB Output is correct
8 Correct 10 ms 10348 KB Output is correct
9 Correct 8 ms 10348 KB Output is correct
10 Correct 8 ms 10348 KB Output is correct
11 Correct 8 ms 10348 KB Output is correct
12 Correct 10 ms 10348 KB Output is correct
13 Correct 15 ms 10348 KB Output is correct
14 Correct 16 ms 10348 KB Output is correct
15 Correct 8 ms 10348 KB Output is correct
16 Correct 7 ms 10348 KB Output is correct
17 Correct 12 ms 10348 KB Output is correct
18 Correct 15 ms 10348 KB Output is correct
19 Correct 13 ms 10348 KB Output is correct
20 Correct 9 ms 10348 KB Output is correct
21 Correct 7 ms 10348 KB Output is correct
22 Runtime error 1 ms 876 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -