Submission #398185

#TimeUsernameProblemLanguageResultExecution timeMemory
398185DrearyJokeNautilus (BOI19_nautilus)C++17
100 / 100
245 ms700 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<bool> vb; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.first >> p.second; return i;} template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;} template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.first << ' ' << p.second; return o;} template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;} #define deb(x) cout << '>' << #x << ':' << x << endl; #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define END '\n' #define inf 9e18 #define ff first #define ss second #define pb push_back const int maxN = 500; void solve(){ int n, m, c; cin >> n >> m >> c; vector<bitset<500>> inv(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { char cc; cin >> cc; if (cc == '.') inv[i][j] = 1; } } string s; cin >> s; vector<bitset<500>> ans(n), prev = inv, cur(n); bitset<500> zero; for (int i = 0; i < c; ++i) { for (int j = 0; j < n; ++j) { cur[j] = zero; if (s[i] == 'N' && j < n - 1) cur[j] = (prev[j + 1] & inv[j]); else if (s[i] == 'S' && j > 0) cur[j] = (prev[j - 1] & inv[j]); else if (s[i] == 'E') cur[j] = (prev[j] << 1) & inv[j]; else if (s[i] == 'W') cur[j] = (prev[j] >> 1) & inv[j]; else if (s[i] == '?') cur[j] = (((j > 0) ? prev[j - 1] : zero) | (j < n - 1 ? prev[j + 1] : zero) | (prev[j] >> 1) | (prev[j] << 1)) & inv[j]; } cur.swap(prev); } int tot = 0; for (int i = 0; i < n; ++i) tot += prev[i].count(); cout << tot << END; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; while(t--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...