Submission #1003480

# Submission time Handle Problem Language Result Execution time Memory
1003480 2024-06-20T11:41:42 Z anango Nautilus (BOI19_nautilus) C++17
0 / 100
2 ms 600 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 500;


signed main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    /*#ifdef ONLINE_JUDGE
    	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
    #endif*/ //fast IO

    int n,m,k;
    cin >> n >> m >> k;
    bitset<maxn> B;
    bitset<maxn> all0;
    vector<bitset<maxn>> grid(n,B);
    vector<bitset<maxn>> allowed(n,B);
    for (int i=0; i<n; i++) {
        string s;
        cin >> s;
        bitset<maxn> B1;
        for (int j=0; j<m; j++) {
            if (s[j]=='#') {
                B1[j] = 0;
            }
            else {
                B1[j] = 1;
            }
        }
        grid[i] = allowed[i] = B1;
    }
    for (int let=0; let<k; let++) {
        char c;
        cin >> c;
        //cout << let << " " << c << endl;
        if (c=='N') {
            for (int i=1; i<n; i++) {
                allowed[i-1] = allowed[i];
            }
            allowed[n-1] = all0;
        }
        else if (c=='S') {
            
            for (int i=n-2; i>=0; i--) {
                //cout << "downing " << i << endl;
                allowed[i+1] = allowed[i];
            }
            allowed[0] = all0;
        }
        else if (c=='W') {
            for (int i=0; i<n; i++) {
                allowed[i] >>= 1;
            }
        }
        else if (c=='E') {
            for (int i=0; i<n; i++) {
                allowed[i] <<= 1;
            }
        }
        else if (c=='?') {
            //cout << "d" << let << endl;
            vector<bitset<maxn>> allowed2(n,all0);
            //cout << "e" << let << endl;
            for (int i=0; i<n; i++) {
                //cout << "doing " << i << endl;
                allowed2[i] |= allowed[i]>>1;
                allowed2[i] |= allowed[i]<<1;
            }
            for (int i=n-2; i>=0; i--) {
                //cout << i << endl;
                allowed2[i+1] |= allowed[i];
            }
            for (int i=1; i<n; i++) {
                //cout << i << endl;
                allowed2[i-1] |= allowed[i];
            }
            allowed=allowed2;

        }
        else {
            assert(false);
        }

        for (int i=0; i<n; i++) {
            allowed[i] &= grid[i];
        }
        
    }

    int answer = 0;
    for (int i=0; i<n; i++) {
        answer+=allowed[i].count();
    }
    cout << answer << endl;

    
}

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -