Submission #285102

# Submission time Handle Problem Language Result Execution time Memory
285102 2020-08-28T10:18:14 Z 2fat2code Nautilus (BOI19_nautilus) C++17
100 / 100
105 ms 760 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define sz() size()
#define fr first
#define sc second
//#define int long long
#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)

const int mod = 1e9 + 7;

ll lgp(ll a,ll b){
    ll res = 1LL, pop = a;
    for(int i=0;(1LL << i)<=b;i++){
        if(b & (1LL << i)){
            res = (res * pop) % mod;
        }
        pop = (pop * pop) % mod;
    }
    return res;
}

ll inv(ll a){
    return lgp(a, mod - 2LL);
}

const int mmax = 505;

int n,m,k;
char c[mmax][mmax];
string s;
bitset<mmax>pr[mmax],curr[mmax],obstacole[mmax];

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    srand(chrono::steady_clock::now().time_since_epoch().count());
  //  freopen("input.in","r",stdin);
    cin >> n >> m >> k;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> c[i][j];
            curr[i][j] = (c[i][j] == '.' ? 1 : 0);
            obstacole[i][j] = (c[i][j] == '.' ? 1 : 0);
        }
    }
    cin >> s;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=n;j++){
            swap(curr[j],pr[j]);
        }
        for(int j=1;j<=n;j++){
            curr[j] ^= curr[j];
        }
        if(s[i - 1] == 'N' || s[i - 1] == '?'){
            for(int j=1;j<=n;j++){
                if(j <= n - 1){
                    curr[j] |= pr[j + 1];
                }
            }
        }
        if(s[i - 1] == 'S' || s[i - 1] == '?'){
            for(int j=1;j<=n;j++){
                if(j >= 2){
                    curr[j] |= pr[j - 1];
                }
            }
        }
        if(s[i - 1] == 'E' || s[i - 1] == '?'){
            for(int j=1;j<=n;j++){
                curr[j] |= (pr[j] << 1);
            }
        }
        if(s[i - 1] == 'W' || s[i - 1] == '?'){
            for(int j=1;j<=n;j++){
                curr[j] |= (pr[j] >> 1);
            }
        }
        for(int j=1;j<=n;j++){
            curr[j] &= obstacole[j];
        }
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        ans += curr[i].count();
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 61 ms 640 KB Output is correct
23 Correct 64 ms 640 KB Output is correct
24 Correct 63 ms 640 KB Output is correct
25 Correct 62 ms 760 KB Output is correct
26 Correct 61 ms 640 KB Output is correct
27 Correct 81 ms 640 KB Output is correct
28 Correct 82 ms 640 KB Output is correct
29 Correct 89 ms 640 KB Output is correct
30 Correct 82 ms 740 KB Output is correct
31 Correct 84 ms 760 KB Output is correct
32 Correct 105 ms 640 KB Output is correct
33 Correct 99 ms 640 KB Output is correct
34 Correct 100 ms 640 KB Output is correct
35 Correct 97 ms 640 KB Output is correct
36 Correct 97 ms 736 KB Output is correct