Submission #894823

# Submission time Handle Problem Language Result Execution time Memory
894823 2023-12-29T04:49:15 Z vjudge1 Nautilus (BOI19_nautilus) C++17
29 / 100
1000 ms 472 KB
//Bismillahir-Rahmanir-Rahim
#include <bits/stdc++.h>
            
using namespace std;
         
#define flash ios_base::sync_with_stdio(0),cin.tie(0)
#define pb push_back
#define ll long long
#define ld long double
#define dbg(x) cerr << #x << " = " << x << "\n";
#define ff first
#define ss second
     
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma comment (linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
    
const long long INF = 1e9 + 7;
const long long MOD = 1e9 + 7;
const int maxn = 2e5 + 10;
const int lg = 20;

int n, m, ans, ok, sz, used[123][123];
char a[123][123];
string s;

void check(int x, int y, int id) {
	if (id > sz) {
		used[x][y] = 1;
		return;
	}
	if (s[id] == 'N') {
		if (x - 1 >= 1 && x - 1 <= n && a[x - 1][y] == '.') {
			check(x - 1, y, id + 1);
		}
	}
	if (s[id] == 'S') {
		if (x + 1 >= 1 && x + 1 <= n && a[x + 1][y] == '.') {
			check(x + 1, y, id + 1);
		}
	}
	if (s[id] == 'W') {
		if (y - 1 >= 1 && y - 1 <= m && a[x][y - 1] == '.') {
			check(x, y - 1, id + 1);
		}
	}
	if (s[id] == 'E') {
		if (y + 1 >= 1 && y + 1 <= m && a[x][y + 1] == '.') {
			check(x, y + 1, id + 1);
		}
	}
	if (s[id] == '?') {
		if (x - 1 >= 1 && x - 1 <= n && a[x - 1][y] == '.') {
			check(x - 1, y, id + 1);
		}
		if (x + 1 >= 1 && x + 1 <= n && a[x + 1][y] == '.') {
			check(x + 1, y, id + 1);
		}
		if (y - 1 >= 1 && y - 1 <= m && a[x][y - 1] == '.') {
			check(x, y - 1, id + 1);
		}
		if (y + 1 >= 1 && y + 1 <= m && a[x][y + 1] == '.') {
			check(x, y + 1, id + 1);
		}
	}
}

void press_F_() {
	cin >> n >> m >> sz;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}
	cin >> s;
	s = "*" + s;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == '.') {
				ok = 0;
				check(i, j, 1);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == '.' && used[i][j] == 1) {
				ans++;
			}
		}
	}
	cout << ans;
}
   
int main() {
    flash;
    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; i++) {
        press_F_();
    }
    //Respa gold 2023-2024 InshAllah
    return 0;
}
/*
Maybe not today and tomorrow, but InshAllah one day I will reach expert
*/
// g++ -std=c++17 main.cpp
// ./a.out
# Verdict Execution time Memory Grader output
1 Correct 12 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 472 KB Output is correct
7 Execution timed out 1074 ms 348 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 472 KB Output is correct
7 Execution timed out 1074 ms 348 KB Time limit exceeded
8 Halted 0 ms 0 KB -