Submission #968691

#TimeUsernameProblemLanguageResultExecution timeMemory
968691NintsiChkhaidzeNautilus (BOI19_nautilus)C++17
100 / 100
204 ms157800 KiB
#include <bits/stdc++.h> #define ll long long #define s second #define f first #define pb push_back #define left (h*2),l,(l + r)/2 #define right (h*2+1),(l+r)/2 + 1,r #define pii pair <int,int> using namespace std; const int N = 503; char a[N][N]; vector <pii> neighbours = {{0,1}, {0,-1}, {1,0}, {-1,0}}; int n,m; bitset <501> dp[N][5003]; bitset <501> mask[N]; bool valid(int x,int y){ return (x >= 1 && x <= n && y >= 1 && y <= m && a[x][y] == '.'); } signed main(){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int k; cin>>n>>m>>k; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++){ cin >> a[i][j]; if (a[i][j] == '.') dp[i][0][j] = 1,mask[i][j] = 1; else mask[i][j] = 0; } string s; cin>>s; map <char,pii> mp; mp['N'] = {-1,0}; mp['S'] = {1,0}; mp['E'] = {0,+1}; mp['W'] = {0,-1}; s='%' + s; for (int i = 1; i <= k; i++){ for (int x = 1; x <= n; x++){ bitset <501> nw; if (s[i] == 'E' || s[i] == '?'){ nw |= (dp[x][i - 1] << 1) & mask[x]; } if (s[i] == 'W' || s[i] == '?'){ nw |= (dp[x][i - 1] >> 1) & mask[x]; } if (s[i] == 'N' || s[i] == '?'){ nw |= dp[x + 1][i - 1] & mask[x]; } if (s[i] == 'S' || s[i] == '?'){ nw |= dp[x - 1][i - 1] & mask[x]; } dp[x][i] = nw; } } int ans=0; for (int i = 1; i <= n; i++) ans += dp[i][k].count(); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...