Submission #1096138

# Submission time Handle Problem Language Result Execution time Memory
1096138 2024-10-04T01:10:50 Z cpptowin Nautilus (BOI19_nautilus) C++17
100 / 100
164 ms 784 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define bitcount(x) __builtin_popcountll(x)
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ss(x) (int)x.size()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
void add(int &x, int k)
{
    x += k;
    x %= mod;
    if(x < 0) x += mod;
}
void del(int &x, int k)
{
    x -= k;
    x %= mod;
    if(x < 0) x += mod;
}
bitset<505> arr[505],f[2][505];
int n,m,k;
char a[5010];
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> k;
    fo(i,1,n) 
    {
        fo(j,1,m)
        {
            char t;
            cin >> t;
            if(t == '.') arr[i][j] = f[0][i][j] = 1;
        }
    }
    fo(i,1,k) cin >> a[i];
    fo(i,1,k)
    {
        if(a[i] == 'N') 
        {
            fo(j,1,n) f[i % 2][j] = f[1 - i % 2][j + 1] & arr[j];
        }
        else if(a[i] == 'S')
        {
            fo(j,1,n) f[i % 2][j] = f[1 - i % 2][j - 1] & arr[j];
        }
        else if(a[i] == 'W')
        {
            fo(j,1,n) f[i % 2][j] = (f[1 - i % 2][j] >> 1) & arr[j];
        }
        else if(a[i] == 'E')
        {
            fo(j,1,n) f[i % 2][j] = (f[1 - i % 2][j] << 1) & arr[j];
        }
        else 
        {
            fo(j,1,n) f[i % 2][j] = (f[1 - i % 2][j + 1]|f[1 - i % 2][j - 1]|
            (f[1 - i % 2][j] << 1) | (f[1 - i & 1][j] >> 1)) & arr[j];
        }
    }
    int ans = 0;
    fo(i,1,n) ans += f[k & 1][i].count();
    cout << ans;
}

Compilation message

nautilus.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main()
      | ^~~~
nautilus.cpp: In function 'int main()':
nautilus.cpp:100:43: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
  100 |             (f[1 - i % 2][j] << 1) | (f[1 - i & 1][j] >> 1)) & arr[j];
      |                                         ~~^~~
nautilus.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 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 348 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 348 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 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 468 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 344 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 1 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 348 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 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 468 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 344 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 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 70 ms 604 KB Output is correct
23 Correct 72 ms 784 KB Output is correct
24 Correct 69 ms 604 KB Output is correct
25 Correct 68 ms 600 KB Output is correct
26 Correct 66 ms 604 KB Output is correct
27 Correct 120 ms 600 KB Output is correct
28 Correct 126 ms 604 KB Output is correct
29 Correct 124 ms 600 KB Output is correct
30 Correct 123 ms 600 KB Output is correct
31 Correct 120 ms 604 KB Output is correct
32 Correct 160 ms 608 KB Output is correct
33 Correct 162 ms 780 KB Output is correct
34 Correct 161 ms 600 KB Output is correct
35 Correct 160 ms 600 KB Output is correct
36 Correct 164 ms 604 KB Output is correct