답안 #889958

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889958 2023-12-20T10:20:49 Z vjudge1 Nautilus (BOI19_nautilus) C++17
29 / 100
1000 ms 230904 KB
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef long double ld;

#define all(x) x.begin(),x.end()
#define pb push_back
#define ent "\n"

const int maxn = (int)2e5 + 13;
const ll inf = (long long)1e18 + 20;
const int mod = (int)1e9 + 7;

int n,m,k;
char a[1001][1001];
int used[1001][1001];

int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

bool check(int i,int j){
	if(1 <= i && i <= n && 1 <= j && j <= m && a[i][j] == '.')return 1;
	else return 0;
}

map<char,pair<int,int>>mp;
string s;

void bfs(int x,int y){
	queue<pair<pair<int,int>,int>>q;
	q.push({{x,y},1});
	while(q.size()){
		pair<pair<int,int>,int>v = q.front();
		q.pop();
		if(v.second == k + 1){
			used[v.first.first][v.first.second] = 1;
			// cout << v.first.first << ' ' << v.first.second << ent;
			// cout << x << ' ' << y << ent << ent;
			continue;
		}
		for(int i = 0 ; i < 4 ; i ++){
			int xx = v.first.first + dx[i],yy = v.first.second + dy[i];
			if(check(xx,yy)){
				if(s[v.second] == '?')q.push({{xx,yy},v.second + 1});
				else{
					if(mp[s[v.second]].first == dx[i] && mp[s[v.second]].second == dy[i]){
						q.push({{xx,yy},v.second + 1});
						// cout << v.first.first << ' ' << v.first.second << ent;
						// cout << xx << ' ' << yy << ' ' << dx[i] << ' ' << dy[i] << ' ' << v.second << ent;
					}	
				}
			}
		}
	}
}

void solve(){
	cin >> n >> m >> k;
	for(int i = 1 ; i <= n ; i ++){
		for(int j = 1 ; j <= m ; j ++){
			cin >> a[i][j];
		}
	}
	mp['N'] = {-1,0};
	mp['E'] = {0,1};
	mp['S'] = {1,0};
	mp['W'] = {0,-1};
	cin >> s;
	s = '+' + s;
	for(int i = 1 ; i <= n ; i ++){
		for(int j = 1 ; j <= m ; j ++){
			if(a[i][j] == '.'){
				int x = i,y = j;
				bfs(i,j);
			}
		}
	}
	int ans = 0;
	for(int i = 1 ; i <= n ; i ++){
		for(int j = 1 ; j <= n ; j ++)ans += used[i][j];
	}
	cout << ans;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t --){
		solve();
	}
	return 0;
}

Compilation message

nautilus.cpp: In function 'void solve()':
nautilus.cpp:103:9: warning: unused variable 'x' [-Wunused-variable]
  103 |     int x = i,y = j;
      |         ^
nautilus.cpp:103:15: warning: unused variable 'y' [-Wunused-variable]
  103 |     int x = i,y = j;
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 4696 KB Output is correct
2 Correct 3 ms 4440 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 4696 KB Output is correct
2 Correct 3 ms 4440 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Execution timed out 1069 ms 230904 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 4696 KB Output is correct
2 Correct 3 ms 4440 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Execution timed out 1069 ms 230904 KB Time limit exceeded
8 Halted 0 ms 0 KB -