# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1265818 | mingga | Nautilus (BOI19_nautilus) | C++20 | 1095 ms | 328 KiB |
// Author: caption_mingle
#include "bits/stdc++.h"
using namespace std;
#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const int inf = 2e9;
int n, m, k, idd[150];
pair<int, int> d[4] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
bitset<505> f[2][505], a[505];
signed main() {
cin.tie(0) -> sync_with_stdio(0);
#define task ""
if(fopen(task ".INP", "r")) {
freopen(task ".INP", "r", stdin);
freopen(task ".OUT", "w", stdout);
}
cin >> n >> m >> k;
idd['N'] = 1;
idd['S'] = 0;
idd['E'] = 3;
idd['W'] = 2;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
char c; cin >> c;
f[0][i][j] = (c == '.');
a[i][j] = f[0][i][j];
}
}
string s; cin >> s;
for(int t = 1; t <= k; t++) {
char c = s[t - 1];
int id = t & 1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
f[id][i][j] = 0;
if(c == '?') {
if(a[i][j] == 0) continue;
for(int z = 0; z < 4; z++) {
int nx = i + d[z].fi, ny = j + d[z].se;
if(nx < 1 or ny < 1 or nx > n or ny > m) continue;
f[id][i][j] = f[id ^ 1][nx][ny];
if(f[id][i][j]) break;
}
} else {
auto [nx, ny] = d[idd[c]];
int x = i + nx, y = j + ny;
if(x < 1 or y < 1 or x > n or y > m) continue;
f[id][i][j] = (f[id ^ 1][x][y] && a[i][j]);
}
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
ans += f[k & 1][i].count();
}
cout << ans << ln;
cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |