fork download
  1. #include<bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4.  
  5. bitset<505> dp[505][5005];
  6. bitset<505> a[505];
  7.  
  8. signed main()
  9. {
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(NULL);
  12. int n,m,l;
  13. cin >> n >> m >> l;
  14. for(int i=1;i<=n;i++) {
  15. for(int j=1;j<=m;j++) {
  16. char c;
  17. cin >> c;
  18. a[i] <<= 1;
  19. if(c=='.') {
  20. a[i]|=1;
  21. }
  22. }
  23. dp[i][0]=a[i];
  24. }
  25. string s;
  26. cin >> s;
  27. s='.'+s;
  28. int ans=0;
  29. for(int j=1;j<=l;j++) {
  30. for(int i=1;i<=n;i++) {
  31. if(s[j]=='W') {
  32. dp[i][j]=(dp[i][j-1] << 1) & a[i];
  33. }
  34. if(s[j]=='E') {
  35. dp[i][j]=(dp[i][j-1] >> 1) & a[i];
  36. }
  37. if(s[j]=='N') {
  38. dp[i][j]=dp[i+1][j-1] & a[i];
  39. }
  40. if(s[j]=='S') {
  41. dp[i][j]=dp[i-1][j-1] & a[i];
  42. }
  43. if(s[j]=='?') {
  44. dp[i][j]=((dp[i][j-1] << 1) | (dp[i][j-1] >> 1) | dp[i-1][j-1] | dp[i+1][j-1]) & a[i];
  45. }
  46. if(j==l) ans+=dp[i][j].count();
  47. }
  48. }
  49. cout << ans;
  50. return 0;
  51. }
  52.  
  53. /*
  54. ██╗░░██╗██╗░░██╗░█████╗░███╗░░██╗░██████╗░ ░██████╗██╗██╗░░░██╗ ░█████╗░██╗░░░██╗████████╗███████╗
  55. ██║░██╔╝██║░░██║██╔══██╗████╗░██║██╔════╝░ ██╔════╝██║██║░░░██║ ██╔══██╗██║░░░██║╚══██╔══╝██╔════╝
  56. █████═╝░███████║███████║██╔██╗██║██║░░██╗░ ╚█████╗░██║██║░░░██║ ██║░░╚═╝██║░░░██║░░░██║░░░█████╗░░
  57. ██╔═██╗░██╔══██║██╔══██║██║╚████║██║░░╚██╗ ░╚═══██╗██║██║░░░██║ ██║░░██╗██║░░░██║░░░██║░░░██╔══╝░░
  58. ██║░╚██╗██║░░██║██║░░██║██║░╚███║╚██████╔╝ ██████╔╝██║╚██████╔╝ ╚█████╔╝╚██████╔╝░░░██║░░░███████╗
  59. ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝░╚═════╝░ ╚═════╝░╚═╝░╚═════╝░ ░╚════╝░░╚═════╝░░░░╚═╝░░░╚══════╝
  60. */
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty