Submission #503021

# Submission time Handle Problem Language Result Execution time Memory
503021 2022-01-07T00:05:09 Z Victor Nautilus (BOI19_nautilus) C++17
100 / 100
148 ms 724 KB
// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout<<#x<<" = "<<x<<endl

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;

const int INF = 1'000'000'007;

bitset<501>grid[501],dp[2][501];
int rows,cols,m;
string moves;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);

    cin>>rows>>cols>>m;
    rep(i,0,rows) {
        string row;
        cin>>row;
        rep(j,0,cols)grid[i][j]=row[j]=='.';
        dp[0][i]=grid[i];
    }

    int cur=0,nxt=1;
    cin>>moves;
    trav(dir,moves) {
        rep(i,0,rows)dp[nxt][i].reset();
        if(dir=='N'||dir=='?') rep(i,1,rows)dp[nxt][i-1]=dp[cur][i];
        if(dir=='S'||dir=='?') rep(i,0,rows-1)dp[nxt][i+1]|=dp[cur][i];
        if(dir=='W'||dir=='?') rep(i,0,rows)dp[nxt][i]|=dp[cur][i]>>1;
        if(dir=='E'||dir=='?') rep(i,0,rows)dp[nxt][i]|=dp[cur][i]<<1;
        rep(i,0,rows) dp[nxt][i]&=grid[i];
        swap(cur,nxt);
    }

    int ans=0;
    rep(i,0,rows) {
        ans+=dp[cur][i].count();
        //string row=string(cols,'.');
        //rep(j,0,cols)if(dp[cur][i][j])row[j]='#';
        //cout<<row<<endl;
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 79 ms 584 KB Output is correct
23 Correct 83 ms 708 KB Output is correct
24 Correct 78 ms 584 KB Output is correct
25 Correct 79 ms 588 KB Output is correct
26 Correct 77 ms 584 KB Output is correct
27 Correct 118 ms 724 KB Output is correct
28 Correct 118 ms 664 KB Output is correct
29 Correct 117 ms 664 KB Output is correct
30 Correct 122 ms 664 KB Output is correct
31 Correct 115 ms 588 KB Output is correct
32 Correct 144 ms 660 KB Output is correct
33 Correct 144 ms 660 KB Output is correct
34 Correct 148 ms 664 KB Output is correct
35 Correct 145 ms 588 KB Output is correct
36 Correct 145 ms 664 KB Output is correct