Submission #285099

# Submission time Handle Problem Language Result Execution time Memory
285099 2020-08-28T10:16:50 Z 2fat2code Nautilus (BOI19_nautilus) C++17
66 / 100
1000 ms 640 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++){
            for(int t=1;t<=m;t++){
                curr[j][t] = 0;
            }
        }
        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 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 484 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 544 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 484 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Execution timed out 1053 ms 640 KB Time limit exceeded
23 Halted 0 ms 0 KB -