Submission #1126703

#TimeUsernameProblemLanguageResultExecution timeMemory
1126703FucKanhNautilus (BOI19_nautilus)C++20
100 / 100
145 ms552 KiB
#include<bits/stdc++.h> #define ll long long #define int ll #define pii pair<int,int> using namespace std; const int maxn = 505; int n,m,q; bitset<maxn> a[maxn], fix[maxn]; string s; namespace SUB1 { int b[maxn][maxn]; void solve() { for (int i = 1; i <= q; i++) { if (s[i-1] == 'W') { for (int x = 1; x <= n; x++) { for (int y = 1; y <= m; y++) { b[x][y] = a[x][y+1]; } } } else if (s[i-1] == 'E') { for (int x = 1; x <= n; x++) { for (int y = 1; y <= m; y++) { b[x][y] = a[x][y-1]; } } } else if (s[i-1] == 'S') { for (int x = 1; x <= n; x++) { for (int y = 1; y <= m; y++) { b[x][y] = a[x-1][y]; } } } else if (s[i-1] == 'N') { for (int x = 1; x <= n; x++) { for (int y = 1; y <= m; y++) { b[x][y] = a[x+1][y]; } } } else { for (int x = 1; x <= n; x++) { for (int y = 1; y <= m; y++) { b[x][y] = a[x-1][y] || a[x+1][y] || a[x][y-1] || a[x][y+1]; } } } for (int x = 1; x <= n; x++) { for (int y = m; y >= 1; y--) { cout << a[x][y] << " "; } cout << endl; } cout << endl; for (int x = 1; x <= n; x++) { for (int y = 1; y <= m; y++) { a[x][y] = b[x][y] && fix[x][y]; } } for (int x = 1; x <= n; x++) { for (int y = m; y >= 1; y--) { cout << a[x][y] << " "; } cout << endl; } cout << endl; } int ans = 0; for (int x = 1; x <= n; x++) { for (int y = 1; y <= m; y++) { ans += a[x][y]; } } cout << ans; } } namespace SUB2 { bitset<maxn> b[maxn]; void solve() { for (int i = 1; i <= q; i++) { if (s[i-1] == 'W') { for (int x = 1; x <= n; x++) { b[x] = (a[x] << 1) & fix[x]; } } else if (s[i-1] == 'E') { for (int x = 1; x <= n; x++) { b[x] = (a[x] >> 1) & fix[x]; } } else if (s[i-1] == 'S') { for (int x = 1; x <= n; x++) { b[x] = a[x-1] & fix[x]; } } else if (s[i-1] == 'N') { for (int x = 1; x <= n; x++) { b[x] = a[x+1] & fix[x]; } } else { for (int x = 1; x <= n; x++) { b[x] = (a[x+1] | a[x-1] | (a[x] << 1) | (a[x] >> 1)) & fix[x]; } } for (int x = 1; x <= n; x++) a[x] = b[x]; } int ans = 0; for (int x = 1; x <= n; x++) { ans += a[x].count(); } cout << ans; } } void solve() { cin >> n >> m >> q; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { char c; cin >> c; if (c == '.') fix[i][m-j+1] = a[i][m-j+1] = 1; } } cin >> s; SUB2::solve(); } signed main() { cin.tie(0) -> sync_with_stdio(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...