Submission #643727

# Submission time Handle Problem Language Result Execution time Memory
643727 2022-09-22T19:42:30 Z amoorj Nautilus (BOI19_nautilus) C++17
66 / 100
1000 ms 14796 KB
#pragma GCC optimize ("O3,unroll-loops,Ofast")
#pragma GCC target ("avx2,bmi,bmi2,popcnt")
#include <bits/stdc++.h>
#define F first
#define pb push_back
#define sz size()
#define S second
using namespace std;
typedef long long int ll;

const int N = 505, M = 5005;
int r,c,m;
string wef,s[N];
bitset<N*N> dp[M];

int get(int x,int y){
	return (y * c + x);
}
pair<int,int> cor(int i){
	return make_pair(i/c,i%c);
}
inline void init(){
}
inline void input(){
	cin >> r >> c >> m;
	for(int i=0;i<r;i++)
		cin >> s[i];
	cin >> wef;
}
inline void solve(){
	for(int i=0;i<r*c;i++){
		pair<int,int> few = cor(i);
		int x = few.S, y = few.F;
		dp[0][i] = (s[y][x] == '.');
	}
	for(int j=1;j<=m;j++){
		for(int i=0;i<r*c;i++){
			pair<int,int> few = cor(i);
			int x = few.S, y = few.F;
			if(s[y][x] == '#'){
				dp[j][i] = false;
				continue;
			}
			if((wef[j-1] == 'S' || wef[j-1] == '?') && y-1 >= 0)
				dp[j][i] = dp[j][i] | dp[j-1][get(x,y-1)];
			
			if((wef[j-1] == 'N' || wef[j-1] == '?') && y+1 < r)
				dp[j][i] = dp[j][i] | dp[j-1][get(x,y+1)];
			
			if((wef[j-1] == 'E' || wef[j-1] == '?') && x-1 >= 0)
				dp[j][i] = dp[j][i] | dp[j-1][get(x-1,y)];
			
			if((wef[j-1] == 'W' || wef[j-1] == '?') && x+1 < c)
				dp[j][i] = dp[j][i] | dp[j-1][get(x+1,y)];
		}
	}
	int cnt = 0;
	for(int i=0;i<r*c;i++){
//		if(i % c == 0)
//			cout << endl;
//		cout << dp[i][m];
		cnt += dp[m][i];
	}
	cout << cnt;
}
int main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	init();
	int queries = 1;
//	cin >> queries;
	while(queries--){
		input();
		solve();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 852 KB Output is correct
2 Correct 9 ms 864 KB Output is correct
3 Correct 11 ms 872 KB Output is correct
4 Correct 10 ms 852 KB Output is correct
5 Correct 9 ms 852 KB Output is correct
6 Correct 6 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 852 KB Output is correct
2 Correct 9 ms 864 KB Output is correct
3 Correct 11 ms 872 KB Output is correct
4 Correct 10 ms 852 KB Output is correct
5 Correct 9 ms 852 KB Output is correct
6 Correct 6 ms 888 KB Output is correct
7 Correct 9 ms 852 KB Output is correct
8 Correct 12 ms 768 KB Output is correct
9 Correct 13 ms 852 KB Output is correct
10 Correct 11 ms 852 KB Output is correct
11 Correct 7 ms 852 KB Output is correct
12 Correct 12 ms 800 KB Output is correct
13 Correct 12 ms 852 KB Output is correct
14 Correct 13 ms 832 KB Output is correct
15 Correct 10 ms 884 KB Output is correct
16 Correct 6 ms 852 KB Output is correct
17 Correct 14 ms 852 KB Output is correct
18 Correct 14 ms 852 KB Output is correct
19 Correct 13 ms 776 KB Output is correct
20 Correct 10 ms 836 KB Output is correct
21 Correct 6 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 852 KB Output is correct
2 Correct 9 ms 864 KB Output is correct
3 Correct 11 ms 872 KB Output is correct
4 Correct 10 ms 852 KB Output is correct
5 Correct 9 ms 852 KB Output is correct
6 Correct 6 ms 888 KB Output is correct
7 Correct 9 ms 852 KB Output is correct
8 Correct 12 ms 768 KB Output is correct
9 Correct 13 ms 852 KB Output is correct
10 Correct 11 ms 852 KB Output is correct
11 Correct 7 ms 852 KB Output is correct
12 Correct 12 ms 800 KB Output is correct
13 Correct 12 ms 852 KB Output is correct
14 Correct 13 ms 832 KB Output is correct
15 Correct 10 ms 884 KB Output is correct
16 Correct 6 ms 852 KB Output is correct
17 Correct 14 ms 852 KB Output is correct
18 Correct 14 ms 852 KB Output is correct
19 Correct 13 ms 776 KB Output is correct
20 Correct 10 ms 836 KB Output is correct
21 Correct 6 ms 852 KB Output is correct
22 Execution timed out 1085 ms 14796 KB Time limit exceeded
23 Halted 0 ms 0 KB -