| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1367898 | dzhoz0 | Nautilus (BOI19_nautilus) | C++20 | 1094 ms | 580 KiB |
/*
it could have been better :)
it will next time ;)
*/
#include <bits/stdc++.h>
using namespace std;
#define INF 1e18
#define f first
#define s second
#define pii pair<int, int>
#define vi vector<int>
const int MOD = 1'000'000'000 + 7;
void setIO(string name = "")
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef LOCAL
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#else
if (!name.empty())
{
freopen((name + ".INP").c_str(), "r", stdin);
freopen((name + ".OUT").c_str(), "w", stdout);
}
#endif
}
const int MAXN = 500;
const int MAXK = 5000;
int n, m, l;
bool a[MAXN + 5][MAXN + 5];
bitset<MAXN> prv[MAXN];
bitset<MAXN> cur[MAXN];
map<char, pii> dirs = {
{'N', {-1, 0}},
{'W', {0, -1}},
{'S', {1, 0}},
{'E', {0, 1}}
};
void solve()
{
cin >> n >> m >> l;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
char c; cin >> c;
if(c == '#') a[i][j] = 0;
else a[i][j] = 1;
prv[i][j] = a[i][j];
}
}
string s; cin >> s;
for(int k = 0; k < l; k++) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(prv[i][j]) {
vector<char> dd = {'N', 'S', 'W', 'E'};
if(s[k] != '?') dd = {s[k]};
for(char c : dd) {
auto d = dirs[c];
int ni = d.f + i, nj = d.s + j;
if(ni >= 0 && ni < n && nj >= 0 && nj < m && a[ni][nj]) {
cur[ni][nj] = 1;
}
}
}
}
}
swap(cur, prv);
for(int i = 0; i < n; i++) {
cur[i].reset();
}
}
int res = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
res += prv[i][j];
}
}
cout << res << '\n';
}
signed main()
{
setIO();
int t = 1;
// cin >> t;
while (t--)
solve();
}
Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
