Submission #260275

#TimeUsernameProblemLanguageResultExecution timeMemory
260275NamnamseoNautilus (BOI19_nautilus)C++17
100 / 100
155 ms768 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pp; typedef pair<ll,ll> pll; void cppio(){ ios_base::sync_with_stdio(0); cin.tie(0); } #define all(x) (x).begin(),(x).end() #define pb push_back #define eb emplace_back #define x first #define y second #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define sz(x) (int)(x).size() #define XY(p) p.x, p.y int n, m, k; char c[5010]; typedef bitset<500> BIT[500]; BIT sc[2], ok; int main() { cppio(); cin >> n >> m >> k; { static char buf[510]; rep(i, n) { cin >> buf; rep(j, m) if (buf[j] == '.') ok[i][j] = 1; } } cin >> c; int cur = 0; rep(i, n) sc[cur][i] = ok[i]; rep(ki, k) { auto dp = sc[cur]; switch(c[ki]) { case 'E': rep(i, n) dp[i] = ((dp[i]<<1)&ok[i]); break; case 'W': rep(i, n) dp[i] = ((dp[i]>>1)&ok[i]); break; case 'N': rep(i, n-1) dp[i] = ((dp[i+1])&ok[i]); dp[n-1].reset(); break; case 'S': for(int i=n-1; 1<=i; --i) dp[i] = ((dp[i-1])&ok[i]); dp[0].reset(); break; case '?': auto tmp = sc[cur^1]; rep(i, n) { tmp[i] = ((dp[i]<<1) | (dp[i]>>1)); if (i) tmp[i] |= dp[i-1]; if (i+1 < n) tmp[i] |= dp[i+1]; } rep(i, n) tmp[i] &= ok[i]; cur ^= 1; break; } } int ans = 0; rep(i, n) ans += sc[cur][i].count(); cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...