Submission #1010737

# Submission time Handle Problem Language Result Execution time Memory
1010737 2024-06-29T10:08:42 Z alexdd Nautilus (BOI19_nautilus) C++17
100 / 100
156 ms 756 KB
#include<bits/stdc++.h>
using namespace std;
bitset<505> dp[2][505];
bitset<505> mat[505];
bitset<505> emp;
int n,m,L,p;
void baga_N()
{
    for(int i=1;i<n;i++)
        dp[p][i] |= dp[1-p][i+1];
}
void baga_S()
{
    for(int i=2;i<=n;i++)
        dp[p][i] |= dp[1-p][i-1];
}
void baga_E()
{
    for(int i=1;i<=n;i++)
    {
        bool inainte = dp[p][i][1];
        dp[p][i] |= (dp[1-p][i]<<1);
        dp[p][i][1] = inainte;
    }
}
void baga_W()
{
    for(int i=1;i<=n;i++)
    {
        bool inainte = dp[p][i][m];
        dp[p][i] |= (dp[1-p][i]>>1);
        dp[p][i][m] = inainte;
    }
}
signed main()
{
    cin>>n>>m>>L;
    char ch;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>ch;
            if(ch=='#')
            {
                mat[i][j]=0;
            }
            else
            {
                mat[i][j]=1;
                dp[0][i][j]=1;
            }
        }
    }
    for(int pas=1;pas<=L;pas++)
    {
        p = 1-p;
        cin>>ch;
        for(int i=1;i<=n;i++)
            dp[p][i]=emp;
        if(ch=='?')
        {
            baga_N();
            baga_E();
            baga_S();
            baga_W();
        }
        else if(ch=='N') baga_N();
        else if(ch=='S') baga_S();
        else if(ch=='E') baga_E();
        else baga_W();

        for(int i=1;i<=n;i++)
            dp[p][i] = (dp[p][i] & mat[i]);
    }
    int cnt=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(dp[p][i][j])
                cnt++;
    cout<<cnt;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 444 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 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 444 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 452 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 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 2 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 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 444 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 452 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 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 2 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 92 ms 604 KB Output is correct
23 Correct 89 ms 600 KB Output is correct
24 Correct 91 ms 604 KB Output is correct
25 Correct 91 ms 756 KB Output is correct
26 Correct 89 ms 600 KB Output is correct
27 Correct 130 ms 752 KB Output is correct
28 Correct 131 ms 728 KB Output is correct
29 Correct 123 ms 600 KB Output is correct
30 Correct 125 ms 600 KB Output is correct
31 Correct 126 ms 604 KB Output is correct
32 Correct 151 ms 604 KB Output is correct
33 Correct 154 ms 600 KB Output is correct
34 Correct 156 ms 748 KB Output is correct
35 Correct 156 ms 604 KB Output is correct
36 Correct 153 ms 600 KB Output is correct