Submission #1299633

#TimeUsernameProblemLanguageResultExecution timeMemory
1299633TrieTrNautilus (BOI19_nautilus)C++20
100 / 100
107 ms1068 KiB
#include<bits/stdc++.h>
using namespace std;

void local() {
    #define taskname ""
    if (fopen(taskname".inp", "r")) {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }
}

#define ll long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template<class X, class Y> bool mini(X &a, const Y &b) {return (a > b) ? a = b, true : false;}
template<class X, class Y> bool maxi(X &a, const Y &b) {return (a < b) ? a = b, true : false;}

const int N = 5e2 + 5;

int n, m, k;
bitset<N> vis[2][N];
bitset<N> init[N];

int main() {
    fastio; local();
    cin >> n >> m >> k;
    for(int i = 0; i < n; i++) {
    	for(int j = 0; j < m; j++) {
    		char c; cin >> c;
    		init[i][j] = (c == '.');
    	}
    }
    bool turn = 0;
   	for(int i = 0; i < n; i++) vis[turn][i] = init[i];
   	string s; cin >> s;
   	for(int _ = 0; _ < k; _++) {
   		char dir = s[_];
   		turn ^= 1;
   		for(int i = 0; i < n; i++) vis[turn][i].reset();
   		if(dir == 'N' || dir == '?') {
   			for(int i = 1; i < n; i++) {
   				vis[turn][i - 1] |= vis[turn ^ 1][i];
   			}
   		}
   		if(dir == 'S' || dir == '?') {
   			for(int i = 0; i < n - 1; i++) {
   				vis[turn][i + 1] |= vis[turn ^ 1][i];
   			}
   		}
   		if(dir == 'W' || dir == '?') {
   			for(int i = 0; i < n; i++) {
   				vis[turn][i] |= (vis[turn ^ 1][i] >> 1);
   			}
   		}
   		if(dir == 'E' || dir == '?') {
   			for(int i = 0; i < n; i++) {
   				vis[turn][i] |= (vis[turn ^ 1][i] << 1);
   			}
   		}
   		for(int i = 0; i < n; i++) vis[turn][i] &= init[i];
   	}
  	int cnt = 0;
  	for(int i = 0; i < n; i++) {
  		for(int j = 0; j < m; j++) {
  			cnt += vis[turn][i][j];
  		}
  	}
  	cout << cnt;
}

Compilation message (stderr)

nautilus.cpp: In function 'void local()':
nautilus.cpp:7:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:8:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...