답안 #643719

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643719 2022-09-22T19:34:41 Z amoorj Nautilus (BOI19_nautilus) C++17
66 / 100
1000 ms 14284 KB
#pragma GCC optimize ("O3,unroll-loops")
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 872 KB Output is correct
2 Correct 9 ms 852 KB Output is correct
3 Correct 11 ms 848 KB Output is correct
4 Correct 11 ms 852 KB Output is correct
5 Correct 9 ms 840 KB Output is correct
6 Correct 6 ms 868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 872 KB Output is correct
2 Correct 9 ms 852 KB Output is correct
3 Correct 11 ms 848 KB Output is correct
4 Correct 11 ms 852 KB Output is correct
5 Correct 9 ms 840 KB Output is correct
6 Correct 6 ms 868 KB Output is correct
7 Correct 9 ms 868 KB Output is correct
8 Correct 15 ms 852 KB Output is correct
9 Correct 13 ms 864 KB Output is correct
10 Correct 11 ms 872 KB Output is correct
11 Correct 7 ms 868 KB Output is correct
12 Correct 12 ms 796 KB Output is correct
13 Correct 13 ms 852 KB Output is correct
14 Correct 13 ms 872 KB Output is correct
15 Correct 12 ms 852 KB Output is correct
16 Correct 7 ms 852 KB Output is correct
17 Correct 16 ms 796 KB Output is correct
18 Correct 15 ms 860 KB Output is correct
19 Correct 14 ms 852 KB Output is correct
20 Correct 11 ms 864 KB Output is correct
21 Correct 7 ms 792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 872 KB Output is correct
2 Correct 9 ms 852 KB Output is correct
3 Correct 11 ms 848 KB Output is correct
4 Correct 11 ms 852 KB Output is correct
5 Correct 9 ms 840 KB Output is correct
6 Correct 6 ms 868 KB Output is correct
7 Correct 9 ms 868 KB Output is correct
8 Correct 15 ms 852 KB Output is correct
9 Correct 13 ms 864 KB Output is correct
10 Correct 11 ms 872 KB Output is correct
11 Correct 7 ms 868 KB Output is correct
12 Correct 12 ms 796 KB Output is correct
13 Correct 13 ms 852 KB Output is correct
14 Correct 13 ms 872 KB Output is correct
15 Correct 12 ms 852 KB Output is correct
16 Correct 7 ms 852 KB Output is correct
17 Correct 16 ms 796 KB Output is correct
18 Correct 15 ms 860 KB Output is correct
19 Correct 14 ms 852 KB Output is correct
20 Correct 11 ms 864 KB Output is correct
21 Correct 7 ms 792 KB Output is correct
22 Execution timed out 1076 ms 14284 KB Time limit exceeded
23 Halted 0 ms 0 KB -