답안 #180279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
180279 2020-01-08T14:39:40 Z socho Nautilus (BOI19_nautilus) C++14
66 / 100
46 ms 6220 KB
#include "bits/stdc++.h"
using namespace std;

int a, b, m;
vector<vector<bool> > grid;
string s;

bool valid(int x, int y) {
	// cout << "! " << x << ' ' << y << endl;
	if (x < 0 || y < 0) return false;
	if (x >= a || y >= b) return false;
	return grid[x][y];
}

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

const int MXN = 105, MXM = 105;
bool done[MXN][MXN][MXM];
bool dp[MXN][MXN][MXM];

bool works(int x, int y, int at) {
	if (!valid(x, y)) return false;
	if (at == m) return true;
	if (done[x][y][at]) return dp[x][y][at];
	done[x][y][at] = true;
	if (s[at] == '?') {
		for (int i=0; i<4; i++) {
			if (works(x + dx[i], y + dy[i], at+1)) return dp[x][y][at] = true;
		}
		return dp[x][y][at] = false;
	}
	if (s[at] == 'N') {
		return dp[x][y][at] = works(x-1, y, at+1);
	}
	if (s[at] == 'S') {
		return dp[x][y][at] = works(x+1, y, at+1);
	}
	if (s[at] == 'E') {
		return dp[x][y][at] = works(x, y+1, at+1);
	}
	if (s[at] == 'W') {
		return dp[x][y][at] = works(x, y-1, at+1);
	}
	return dp[x][y][at] = false;
}

char op(char a) {
	if (a == 'N') return 'S';
	if (a == 'S') return 'N';
	if (a == 'E') return 'W';
	if (a == 'W') return 'E';
	return a;
}

int main() {
	
	cin >> a >> b >> m;
	for (int i=0; i<a; i++) {
		string s;
		cin >> s;
		vector<bool> tr(b);
		for (int j=0; j<b; j++) {
			tr[j] = (s[j] == '.');
		}
		grid.push_back(tr);
	}
	cin >> s;
	string t = "";
	for (int i=0; i<m; i++) {
		t += op(s[i]);
	}
	s = t;
	reverse(s.begin(), s.end());
	
	int can = 0;
	for (int i=0; i<a; i++) {
		for (int j=0; j<b; j++) {
			if (works(i, j, 0)) {
				can++;
				// cout << "ok: " << i << ' ' << j << endl;
			}
			// cout << "----" << endl;
		}
	}
	cout << can << endl;
	
	
}
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2424 KB Output is correct
2 Correct 6 ms 2552 KB Output is correct
3 Correct 6 ms 2552 KB Output is correct
4 Correct 5 ms 2424 KB Output is correct
5 Correct 5 ms 2552 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2424 KB Output is correct
2 Correct 6 ms 2552 KB Output is correct
3 Correct 6 ms 2552 KB Output is correct
4 Correct 5 ms 2424 KB Output is correct
5 Correct 5 ms 2552 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 22 ms 2552 KB Output is correct
8 Correct 6 ms 2424 KB Output is correct
9 Correct 6 ms 2552 KB Output is correct
10 Correct 7 ms 2552 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 21 ms 2552 KB Output is correct
13 Correct 11 ms 2552 KB Output is correct
14 Correct 9 ms 2424 KB Output is correct
15 Correct 6 ms 2424 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 17 ms 2552 KB Output is correct
18 Correct 9 ms 2552 KB Output is correct
19 Correct 10 ms 2552 KB Output is correct
20 Correct 8 ms 2552 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2424 KB Output is correct
2 Correct 6 ms 2552 KB Output is correct
3 Correct 6 ms 2552 KB Output is correct
4 Correct 5 ms 2424 KB Output is correct
5 Correct 5 ms 2552 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 22 ms 2552 KB Output is correct
8 Correct 6 ms 2424 KB Output is correct
9 Correct 6 ms 2552 KB Output is correct
10 Correct 7 ms 2552 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 21 ms 2552 KB Output is correct
13 Correct 11 ms 2552 KB Output is correct
14 Correct 9 ms 2424 KB Output is correct
15 Correct 6 ms 2424 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 17 ms 2552 KB Output is correct
18 Correct 9 ms 2552 KB Output is correct
19 Correct 10 ms 2552 KB Output is correct
20 Correct 8 ms 2552 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Runtime error 46 ms 6220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -