Submission #1367618

#TimeUsernameProblemLanguageResultExecution timeMemory
1367618dzhoz0Nautilus (BOI19_nautilus)C++20
66 / 100
1095 ms1092 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];

bool prv[MAXN + 5][MAXN + 5];
bool cur[MAXN + 5][MAXN + 5];

map<char, pii> dirs = {
    {'N', {-1, 0}},
    {'W', {0, -1}},
    {'S', {1, 0}},
    {'E', {0, 1}}
};

void solve()
{
    cin >> n >> m >> l;

    memset(cur, 0, sizeof(cur));

    for(int i = 1; i <= n; i++) {
        for(int j = 1; 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 = 1; i <= n; i++) {
            for(int j = 1; 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 >= 1 && ni <= n && nj >= 1 && nj <= m && a[ni][nj]) {
                            cur[ni][nj] = 1;
                        }
                    }
                }
            }
        }
        swap(cur, prv);
        memset(cur, 0, sizeof(cur));
    }

    int res = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            res += prv[i][j];
        }
    }
    cout << res << '\n';
}

signed main()
{
    setIO();
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}

Compilation message (stderr)

nautilus.cpp: In function 'void setIO(std::string)':
nautilus.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen((name + ".INP").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen((name + ".OUT").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...