Submission #498014

# Submission time Handle Problem Language Result Execution time Memory
498014 2021-12-24T09:11:07 Z AQ0212 Nautilus (BOI19_nautilus) C++17
100 / 100
226 ms 158192 KB
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <cstring>
#include <bitset>

// #pragma GCC optimize("inline")
// #pragma GCC optimize("-fgcse,-fgcse-lm")
// #pragma GCC optimize("-ftree-pre,-ftree-vrp")
// #pragma GCC optimize("-ffast-math")
// #pragma GCC optimize("-fipa-sra")
// #pragma GCC optimize("-fpeephole2")
// #pragma GCC optimize("-fsched-spec")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#define ll long long int
#define pb push_back
#define pll pair < ll , ll >
#define fi first
#define se second
#define all(x) x.begin(), x.end()

using namespace std;
 
ll inf2 = 3e18;

int ans;
bitset < 503 > dp[ 5003 ][ 503 ];
string s;
 
int main (){
	ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    ll n, m, t;
	char c;
 
	cin >> n >> m >> t;
 
	for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= m; j ++){
			cin >> c;
			if(c == '.')
				dp[ 0 ][ i ][ j ] = 1;
		}
	}
 
	cin >> s;
	// s = '#' + s;
	// reverse(all(s));

	for(int k = 1; k <= t; k ++){
		for(int i = 1; i <= n; i ++){
			// if(!dp[ 0 ][ i ][ j ]){
			// 	dp[ k ][ i ] = 0;
			// 	continue;
			// }
			if(s[ k - 1 ] == 'N'/* && i + 1 <= n*/)
				dp[ k ][ i ] |= dp[ k - 1 ][ i + 1 ] & dp[ 0 ][ i ];
			else if(s[ k - 1 ] == 'S'/* && i - 1 > 0*/)
				dp[ k ][ i ] |= dp[ k - 1 ][ i - 1 ] & dp[ 0 ][ i ];
			else if(s[ k - 1 ] == 'W'/* && j + 1 <= m*/)
				dp[ k ][ i ] |= (dp[ k - 1 ][ i ] >> 1) & dp[ 0 ][ i ];
			else if(s[ k - 1 ] == 'E'/* && j - 1 > 0*/)
				dp[ k ][ i ] |= (dp[ k - 1 ][ i ] << 1) & dp[ 0 ][ i ];
			else if(s[ k - 1 ] == '?'){
				dp[ k ][ i ] |= dp[ k - 1 ][ i + 1 ] & dp[ 0 ][ i ];
				dp[ k ][ i ] |= dp[ k - 1 ][ i - 1 ] & dp[ 0 ][ i ];
				dp[ k ][ i ] |= (dp[ k - 1 ][ i ] >> 1) & dp[ 0 ][ i ];
				dp[ k ][ i ] |= (dp[ k - 1 ][ i ] << 1) & dp[ 0 ][ i ];
			}
		}
	}

	// for(int k = 0; k <= t; k ++){
		for(int i = 1; i <= n; i ++){
			for(int j = 1; j <= m; j ++){
				ans += ((int)dp[ t ][ i ][ j ]);
				// cout << dp[ k ][ i ][ j ] << " ";
			}
			// cout << endl;
		}
		// cout << endl;
	// }

	cout << ans;
}
 
/*
 
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
 
3 3 3
#..
.#.
..#

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 1 ms 1356 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 2 ms 1356 KB Output is correct
5 Correct 2 ms 1356 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 1 ms 1356 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 2 ms 1356 KB Output is correct
5 Correct 2 ms 1356 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 1 ms 1356 KB Output is correct
8 Correct 1 ms 1356 KB Output is correct
9 Correct 1 ms 1356 KB Output is correct
10 Correct 1 ms 1356 KB Output is correct
11 Correct 1 ms 1356 KB Output is correct
12 Correct 1 ms 1356 KB Output is correct
13 Correct 1 ms 1356 KB Output is correct
14 Correct 1 ms 1356 KB Output is correct
15 Correct 1 ms 1356 KB Output is correct
16 Correct 1 ms 1356 KB Output is correct
17 Correct 2 ms 1356 KB Output is correct
18 Correct 3 ms 1356 KB Output is correct
19 Correct 2 ms 1356 KB Output is correct
20 Correct 2 ms 1356 KB Output is correct
21 Correct 1 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1356 KB Output is correct
2 Correct 1 ms 1356 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 2 ms 1356 KB Output is correct
5 Correct 2 ms 1356 KB Output is correct
6 Correct 1 ms 1356 KB Output is correct
7 Correct 1 ms 1356 KB Output is correct
8 Correct 1 ms 1356 KB Output is correct
9 Correct 1 ms 1356 KB Output is correct
10 Correct 1 ms 1356 KB Output is correct
11 Correct 1 ms 1356 KB Output is correct
12 Correct 1 ms 1356 KB Output is correct
13 Correct 1 ms 1356 KB Output is correct
14 Correct 1 ms 1356 KB Output is correct
15 Correct 1 ms 1356 KB Output is correct
16 Correct 1 ms 1356 KB Output is correct
17 Correct 2 ms 1356 KB Output is correct
18 Correct 3 ms 1356 KB Output is correct
19 Correct 2 ms 1356 KB Output is correct
20 Correct 2 ms 1356 KB Output is correct
21 Correct 1 ms 1356 KB Output is correct
22 Correct 125 ms 157844 KB Output is correct
23 Correct 125 ms 158024 KB Output is correct
24 Correct 126 ms 158008 KB Output is correct
25 Correct 148 ms 157968 KB Output is correct
26 Correct 127 ms 158116 KB Output is correct
27 Correct 222 ms 158148 KB Output is correct
28 Correct 178 ms 157972 KB Output is correct
29 Correct 177 ms 158024 KB Output is correct
30 Correct 226 ms 158020 KB Output is correct
31 Correct 161 ms 157952 KB Output is correct
32 Correct 202 ms 158020 KB Output is correct
33 Correct 209 ms 158008 KB Output is correct
34 Correct 191 ms 158116 KB Output is correct
35 Correct 193 ms 158192 KB Output is correct
36 Correct 186 ms 158000 KB Output is correct