답안 #496401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
496401 2021-12-21T07:27:29 Z Ierus Nautilus (BOI19_nautilus) C++17
0 / 100
6 ms 6220 KB
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define int short
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
const int N = 5555;
const bool I = 1;
const vector<pair<int,int>> dxy = {{-1,0},{1,0},{0,1},{0,-1}};
int n, m, k, q[5555];
char a[555][555];
bool vis[555][555];
bool used[555][555][555];
bool In(int x, int y){
	return (x <= n && x >= 1 && y <= m && y >= 1);
}
bool bfs(int x, int y, int d = k){
	queue<tuple<int,int,int>> que;
	que.push({x, y, d});
	while(!que.empty()){
		tie(x, y, d) = que.front();
		que.pop();
		if(used[x][y][d]){
			continue;
		}
		used[x][y][d] = true;
		if(!d){
			return true;
		}
		if(q[d] == -1){
			for(auto [f, s] : dxy){
				int x1 = x + f, y1 = y + s;
				if(In(x1, y1) && !used[x1][y1][d-1] && a[x1][y1] != '#'){
					que.push({x1, y1, d-1});
					used[x1][y1][d-1] = true;
				}
			}
		}else{
			int x1 = x + dxy[q[d]].F, y1 = y + dxy[q[d]].S;
			if(In(x1, y1) && a[x1][y1] != '#'&& !used[x1][y1][d-1] ){
				que.push({x1, y1, d-1});
				used[x1][y1][d-1] = true;
			}
		}
	}
	return false;
}
signed main(){
	cin >> n >> m >> k;
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= m; ++j){
			cin >> a[i][j];
		}
	}
	for(int i = 1; i <= k; ++i){
		char r; cin >> r;
		if(r == '?') q[i] = -1;
		if(r == 'N') q[i] = 1;
		if(r == 'S') q[i] = 0;
		if(r == 'E') q[i] = 3;
		if(r == 'W') q[i] = 2;
	}
	long long res = 0;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j){
			if(a[i][j] != '#'){
				vis[i][j] = bfs(i, j, k);
			}
		}
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= m; ++j){
			if(a[i][j] == '#'){
			}else{
				res += vis[i][j];
			}
		}
	}
	cout << res;
};











# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 6220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 6220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 6220 KB Output isn't correct
2 Halted 0 ms 0 KB -