Submission #1088923

# Submission time Handle Problem Language Result Execution time Memory
1088923 2024-09-15T14:36:21 Z Cadoc Nautilus (BOI19_nautilus) C++14
100 / 100
166 ms 1112 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define el cout << '\n'
#define N 505

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

void Solve(){
    cin >> n >> m >> k;
    for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) cin >> c[i][j];
    cin >> s; s = ' ' + s;

    for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) dp[0][i][j] = f[i][j] = (c[i][j] == '.');

    for(int t=1; t<=k; ++t){
       char x = s[t];

       if(x == 'N') for(int i=n-1; i; --i) dp[1][i] |= dp[0][i+1], dp[1][i] &= f[i];
       if(x == 'S') for(int i=2; i<=n; ++i) dp[1][i] |= dp[0][i-1], dp[1][i] &= f[i];
       if(x == 'W') for(int i=1; i<=n; ++i) dp[1][i] |= (dp[0][i]>>1), dp[1][i] &= f[i];
       if(x == 'E') for(int i=1; i<=n; ++i) dp[1][i] |= (dp[0][i]<<1), dp[1][i] &= f[i];
       if(x == '?'){
            for(int i=n-1; i; --i) dp[1][i] |= dp[0][i+1], dp[1][i] &= f[i];
            for(int i=2; i<=n; ++i) dp[1][i] |= dp[0][i-1], dp[1][i] &= f[i];
            for(int i=1; i<=n; ++i) dp[1][i] |= (dp[0][i]>>1), dp[1][i] &= f[i];
            for(int i=1; i<=n; ++i) dp[1][i] |= (dp[0][i]<<1), dp[1][i] &= f[i];
       }

       for(int i=1; i<=n; ++i) dp[0][i] = dp[1][i], dp[1][i].reset();
    }

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

    cout << Ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #define NAME "TAUCHIEN"
    if(fopen(NAME".inp", "r")){
        freopen(NAME".inp", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }

    Solve();
    return 0;
}

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 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 476 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 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 476 KB Output is correct
6 Correct 1 ms 348 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 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 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 344 KB Output is correct
2 Correct 1 ms 344 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 476 KB Output is correct
6 Correct 1 ms 348 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 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 344 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 87 ms 860 KB Output is correct
23 Correct 78 ms 1112 KB Output is correct
24 Correct 78 ms 1044 KB Output is correct
25 Correct 76 ms 860 KB Output is correct
26 Correct 74 ms 860 KB Output is correct
27 Correct 119 ms 1112 KB Output is correct
28 Correct 118 ms 860 KB Output is correct
29 Correct 124 ms 860 KB Output is correct
30 Correct 118 ms 1048 KB Output is correct
31 Correct 117 ms 860 KB Output is correct
32 Correct 148 ms 856 KB Output is correct
33 Correct 147 ms 872 KB Output is correct
34 Correct 154 ms 860 KB Output is correct
35 Correct 154 ms 860 KB Output is correct
36 Correct 166 ms 856 KB Output is correct