Submission #496257

# Submission time Handle Problem Language Result Execution time Memory
496257 2021-12-21T04:13:51 Z kingline Nautilus (BOI19_nautilus) C++17
0 / 100
1 ms 460 KB
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
#define all(data) data.begin(), data.end()
#define endl '\n'
#define ll long long
//#define int long long
#define pii pair < int, int >

using namespace std;

const int N = 2e5 + 5;

int n, m, k, use, used[505][505];
char c[505][505];
bool can[505][505];
string s;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
void bfs(int i, int j) {
    queue < pair < int, pii > > q;
    q.push({0, {i, j}});
    used[i][j] = use;
    while(q.size()) {
        pair < int, pii > z = q.front();
        q.pop();
        int pos = z.first, x = z.second.first, y = z.second.second;
        if(pos == k) {
            can[x][y] = 1;
            continue;
        }
        if(s[pos] == 'N' && x - 1 > 0 && used[x - 1][y] < use && c[x - 1][y] == '.') {
            used[x - 1][y] = use;
            q.push({pos + 1, {x - 1, y}});
        }
        if(s[pos] == 'S' && x + 1 <= n && used[x + 1][y] < use && c[x + 1][y] == '.') {
            used[x + 1][y] = use;
            q.push({pos + 1, {x + 1, y}});
        }
        if(s[pos] == 'W' && y - 1 > 0 && used[x][y - 1] < use && c[x][y - 1] == '.') {
            used[x][y - 1] = use;
            q.push({pos + 1, {x, y - 1}});
        }
        if(s[pos] == 'E' && y + 1 <= m && used[x][y + 1] < use && c[x][y + 1] == '.') {
            used[x][y + 1] = use;
            q.push({pos + 1, {x, y + 1}});
        }
    }
}

main() {
    //file("pieaters");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> c[i][j];
        }
    }
    cin >> s;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(c[i][j] == '.') {
                use++;
                bfs(i, j);
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(can[i][j]) {
                ans++;
            }
        }
    }
    cout << ans;
}






Compilation message

nautilus.cpp:57:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   57 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -