Submission #285102

#TimeUsernameProblemLanguageResultExecution timeMemory
2851022fat2codeNautilus (BOI19_nautilus)C++17
100 / 100
105 ms760 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define all(a) (a).begin(), (a).end() #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define sz() size() #define fr first #define sc second //#define int long long #define mp make_pair #define rc(s) return cout<<s,0 #define rcc(s) cout<<s,exit(0) const int mod = 1e9 + 7; ll lgp(ll a,ll b){ ll res = 1LL, pop = a; for(int i=0;(1LL << i)<=b;i++){ if(b & (1LL << i)){ res = (res * pop) % mod; } pop = (pop * pop) % mod; } return res; } ll inv(ll a){ return lgp(a, mod - 2LL); } const int mmax = 505; int n,m,k; char c[mmax][mmax]; string s; bitset<mmax>pr[mmax],curr[mmax],obstacole[mmax]; int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0); srand(chrono::steady_clock::now().time_since_epoch().count()); // freopen("input.in","r",stdin); cin >> n >> m >> k; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ cin >> c[i][j]; curr[i][j] = (c[i][j] == '.' ? 1 : 0); obstacole[i][j] = (c[i][j] == '.' ? 1 : 0); } } cin >> s; for(int i=1;i<=k;i++){ for(int j=1;j<=n;j++){ swap(curr[j],pr[j]); } for(int j=1;j<=n;j++){ curr[j] ^= curr[j]; } if(s[i - 1] == 'N' || s[i - 1] == '?'){ for(int j=1;j<=n;j++){ if(j <= n - 1){ curr[j] |= pr[j + 1]; } } } if(s[i - 1] == 'S' || s[i - 1] == '?'){ for(int j=1;j<=n;j++){ if(j >= 2){ curr[j] |= pr[j - 1]; } } } if(s[i - 1] == 'E' || s[i - 1] == '?'){ for(int j=1;j<=n;j++){ curr[j] |= (pr[j] << 1); } } if(s[i - 1] == 'W' || s[i - 1] == '?'){ for(int j=1;j<=n;j++){ curr[j] |= (pr[j] >> 1); } } for(int j=1;j<=n;j++){ curr[j] &= obstacole[j]; } } int ans = 0; for(int i=1;i<=n;i++){ ans += curr[i].count(); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...