답안 #1099587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099587 2024-10-11T18:31:58 Z andrei_iorgulescu Nautilus (BOI19_nautilus) C++14
100 / 100
267 ms 154208 KB
#include <bits/stdc++.h>

using namespace std;

int n, m, k;
char a[505][505];
char s[5005];
bitset<250005> dp[5005];
bitset<250005> f_up, f_down, f_left, f_right;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    for (int i = 1; i <= k; i++)
        cin >> s[i];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (a[i][j] == '.')
                dp[0][(i - 1) * m + j] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (a[i][j] == '.')
            {
                if (i - 1 >= 1 and a[i - 1][j] == '.')
                    f_up[(i - 1) * m + j] = 1;
                if (i + 1 <= n and a[i + 1][j] == '.')
                    f_down[(i - 1) * m + j] = 1;
                if (j - 1 >= 1 and a[i][j - 1] == '.')
                    f_left[(i - 1) * m + j] = 1;
                if (j + 1 <= m and a[i][j + 1] == '.')
                    f_right[(i - 1) * m + j] = 1;
            }
        }
    }
    //cout << f_left.count() << ' ' << f_right.count() << ' ' << f_up.count() << ' ' << f_down.count() << endl;
    for (int q = 1; q <= k; q++)
    {
        bitset<250005> bs_up, bs_down, bs_left, bs_right;
        bs_up = dp[q - 1] << m;
        bs_down = dp[q - 1] >> m;
        bs_left = dp[q - 1] << 1;
        bs_right = dp[q - 1] >> 1;
        //cout << bs_left.count() << ' ' << bs_right.count() << ' ' << bs_up.count() << ' ' << bs_down.count() << endl;
        for (int i = 1; i <= n; i++)
        {
            bs_left[(i - 1) * m + 1] = 0;
            bs_right[i * m] = 0;
        }
        //cout << bs_left.count() << ' ' << bs_right.count() << ' ' << bs_up.count() << ' ' << bs_down.count() << endl;
        bs_up &= f_up;
        bs_down &= f_down;
        bs_left &= f_left;
        bs_right &= f_right;
        /*if (q == k)
        {
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= m; j++)
                {
                    cout << (int)bs_left[(i - 1) * m + j];
                }
                cout << endl;
            }
            cout << endl;
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= m; j++)
                {
                    cout << (int)bs_right[(i - 1) * m + j];
                }
                cout << endl;
            }
            cout << endl;
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= m; j++)
                {
                    cout << (int)bs_up[(i - 1) * m + j];
                }
                cout << endl;
            }
            cout << endl;
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= m; j++)
                {
                    cout << (int)bs_down[(i - 1) * m + j];
                }
                cout << endl;
            }
            cout << endl;
        }*/
        //cout << bs_left.count() << ' ' << bs_right.count() << ' ' << bs_up.count() << ' ' << bs_down.count() << endl;
        if (s[q] == '?')
            dp[q] = ((bs_up | bs_down) | bs_left) | bs_right;
        else if (s[q] == 'W')
            dp[q] = bs_right;
        else if (s[q] == 'E')
            dp[q] = bs_left;
        else if (s[q] == 'S')
            dp[q] = bs_up;
        else
            dp[q] = bs_down;
        //cout << dp[q].count() << endl;
        /*for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                cout << (int)dp[q][(i - 1) * m + j];
            }
            cout << endl;
        }
        cout << endl;*/
    }
    cout << dp[k].count();
    return 0;
}

/**
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
**/

/**
average problema de lot juniori pe care stie sa o bage doar un om
**/
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3672 KB Output is correct
2 Correct 5 ms 3676 KB Output is correct
3 Correct 4 ms 3676 KB Output is correct
4 Correct 5 ms 3672 KB Output is correct
5 Correct 5 ms 3672 KB Output is correct
6 Correct 5 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3672 KB Output is correct
2 Correct 5 ms 3676 KB Output is correct
3 Correct 4 ms 3676 KB Output is correct
4 Correct 5 ms 3672 KB Output is correct
5 Correct 5 ms 3672 KB Output is correct
6 Correct 5 ms 3676 KB Output is correct
7 Correct 5 ms 3676 KB Output is correct
8 Correct 5 ms 3676 KB Output is correct
9 Correct 9 ms 3676 KB Output is correct
10 Correct 7 ms 3676 KB Output is correct
11 Correct 5 ms 3696 KB Output is correct
12 Correct 6 ms 3676 KB Output is correct
13 Correct 6 ms 3676 KB Output is correct
14 Correct 5 ms 3580 KB Output is correct
15 Correct 6 ms 3676 KB Output is correct
16 Correct 5 ms 3756 KB Output is correct
17 Correct 5 ms 3760 KB Output is correct
18 Correct 6 ms 3676 KB Output is correct
19 Correct 6 ms 3676 KB Output is correct
20 Correct 5 ms 3676 KB Output is correct
21 Correct 5 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3672 KB Output is correct
2 Correct 5 ms 3676 KB Output is correct
3 Correct 4 ms 3676 KB Output is correct
4 Correct 5 ms 3672 KB Output is correct
5 Correct 5 ms 3672 KB Output is correct
6 Correct 5 ms 3676 KB Output is correct
7 Correct 5 ms 3676 KB Output is correct
8 Correct 5 ms 3676 KB Output is correct
9 Correct 9 ms 3676 KB Output is correct
10 Correct 7 ms 3676 KB Output is correct
11 Correct 5 ms 3696 KB Output is correct
12 Correct 6 ms 3676 KB Output is correct
13 Correct 6 ms 3676 KB Output is correct
14 Correct 5 ms 3580 KB Output is correct
15 Correct 6 ms 3676 KB Output is correct
16 Correct 5 ms 3756 KB Output is correct
17 Correct 5 ms 3760 KB Output is correct
18 Correct 6 ms 3676 KB Output is correct
19 Correct 6 ms 3676 KB Output is correct
20 Correct 5 ms 3676 KB Output is correct
21 Correct 5 ms 3676 KB Output is correct
22 Correct 221 ms 154188 KB Output is correct
23 Correct 238 ms 154180 KB Output is correct
24 Correct 226 ms 154068 KB Output is correct
25 Correct 231 ms 154188 KB Output is correct
26 Correct 227 ms 153940 KB Output is correct
27 Correct 248 ms 154196 KB Output is correct
28 Correct 249 ms 154192 KB Output is correct
29 Correct 252 ms 154196 KB Output is correct
30 Correct 232 ms 154196 KB Output is correct
31 Correct 242 ms 153940 KB Output is correct
32 Correct 248 ms 154208 KB Output is correct
33 Correct 241 ms 154192 KB Output is correct
34 Correct 250 ms 154192 KB Output is correct
35 Correct 243 ms 154192 KB Output is correct
36 Correct 267 ms 153940 KB Output is correct