Submission #1072656

# Submission time Handle Problem Language Result Execution time Memory
1072656 2024-08-24T01:57:44 Z kh0i Nautilus (BOI19_nautilus) C++17
100 / 100
197 ms 1104 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif

using ll = long long;
using pii = pair<int, int>;

#define F first
#define S second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll get_rand(ll l, ll r) {
    assert(l <= r);
    return uniform_int_distribution<ll> (l, r)(rng);
}

const int N = 503;

int n, m, k;
char c[N][N];
bitset<N> f[N], g[N], grid[N];
string s;

void solve(){
    cin >> n >> m >> k;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= m; ++j){
            cin >> c[i][j];
            if(c[i][j] == '.')
                grid[i][j] = 1;
        }
        f[i] = grid[i];
    }

    cin >> s;
    for(char mv : s){
        for(int i = 1; i <= n; ++i)
            g[i] = 0;
        if(mv == '?' or mv == 'N'){
            for(int i = 1; i < n; ++i)
                g[i] |= f[i + 1];
        }
        if(mv == '?' or mv == 'S'){
            for(int i = 2; i <= n; ++i)
                g[i] |= f[i - 1];
        }
        if(mv == '?' or mv == 'W'){
            for(int i = 1; i <= n; ++i)
                g[i] |= f[i] >> 1;
        }
        if(mv == '?' or mv == 'E'){
            for(int i = 1; i <= n; ++i)
                g[i] |= f[i] << 1;
        }

        for(int i = 1; i <= n; ++i)
            f[i] = (g[i] & grid[i]);
    }

    int res = 0;
    for(int i = 1; i <= n; ++i)
        res += f[i].count();

    cout << res;
}

int32_t main() {
    cin.tie(nullptr)->sync_with_stdio(0);
    #define task "troll"
    if(fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int test = 1;
//    cin >> test;
    for(int i = 1; i <= test; ++i){
//        cout << "Case #" << i << ": ";
        solve();
    }
    #ifdef LOCAL
        cerr << "\n[Time]: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    #endif
    return 0;
}

Compilation message

nautilus.cpp: In function 'int32_t main()':
nautilus.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 544 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 544 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 140 ms 860 KB Output is correct
23 Correct 142 ms 1044 KB Output is correct
24 Correct 140 ms 1048 KB Output is correct
25 Correct 138 ms 1048 KB Output is correct
26 Correct 138 ms 1024 KB Output is correct
27 Correct 174 ms 860 KB Output is correct
28 Correct 172 ms 860 KB Output is correct
29 Correct 170 ms 856 KB Output is correct
30 Correct 174 ms 1104 KB Output is correct
31 Correct 170 ms 1024 KB Output is correct
32 Correct 192 ms 860 KB Output is correct
33 Correct 197 ms 1040 KB Output is correct
34 Correct 194 ms 856 KB Output is correct
35 Correct 194 ms 860 KB Output is correct
36 Correct 192 ms 1028 KB Output is correct