Submission #927880

# Submission time Handle Problem Language Result Execution time Memory
927880 2024-02-15T13:32:36 Z KaleemRazaSyed Nautilus (BOI19_nautilus) C++17
100 / 100
142 ms 1368 KB
#include<bits/stdc++.h>
 
using namespace std;
 
const int N = 505;
bitset<N> st[N], newst[N], null[N], W[N], E[N], No[N], S[N];
string s[N];
int r, c, m;
 
inline void update()
{
  for(int i = 0; i < r; i ++)
    st[i] = newst[i], newst[i] = null[i];
}
 
inline void move_West()
{
  for(int i = 0; i < r; i ++)
    newst[i] |= (st[i] >> 1) & W[i];
}
 
inline void move_East()
{
  for(int i = 0; i < r; i ++)
    newst[i] |= (st[i] << 1) & E[i];
}
 
inline void move_North()
{
  for(int i = 0; i + 1 < r; i++)
    newst[i] |= (st[i + 1] & No[i]);
}
 
inline void move_South()
{
  for(int i = 1; i < r; i ++)
    newst[i] |= (st[i - 1] & S[i]);
}
 
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> r >> c >> m;
  for(int i = 0; i < r; i++)
    cin >> s[i];
  string dir;
  cin >> dir;
 
  for(int i = 0; i < r; i ++)
    for(int j = 0; j < c; j++)
      if(s[i][j] == '.')
	{
	  st[i][j] = true;
	  if(j > 0 && s[i][j-1] == '.')
	    W[i][j - 1] = true;
	  if(j + 1 < c && s[i][j+1] == '.')
	    E[i][j + 1] = true;
	  if(i > 0 && s[i-1][j] == '.')
	    No[i-1][j] = true;
	  if(i + 1 < r && s[i+1][j] == '.')
	    S[i+1][j] = true;
	}
  
  for(int i = 0; i < m; i ++)
    {
      
      if(dir[i] == 'N' || dir[i] == '?')
	move_North();
      if(dir[i] == 'S' || dir[i] == '?')
	move_South();
      if(dir[i] == 'E' || dir[i] == '?')
	move_East();
      if(dir[i] == 'W' || dir[i] == '?')
	move_West();
      update();
    }
  
  int ans = 0;
  for(int i = 0; i < r; i++)
    ans += st[i].count();
  cout << ans << endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 360 KB Output is correct
22 Correct 63 ms 1164 KB Output is correct
23 Correct 61 ms 1116 KB Output is correct
24 Correct 61 ms 1116 KB Output is correct
25 Correct 57 ms 1116 KB Output is correct
26 Correct 93 ms 860 KB Output is correct
27 Correct 119 ms 1116 KB Output is correct
28 Correct 101 ms 1112 KB Output is correct
29 Correct 96 ms 1160 KB Output is correct
30 Correct 93 ms 1112 KB Output is correct
31 Correct 92 ms 1072 KB Output is correct
32 Correct 132 ms 1368 KB Output is correct
33 Correct 120 ms 1164 KB Output is correct
34 Correct 142 ms 1092 KB Output is correct
35 Correct 113 ms 1116 KB Output is correct
36 Correct 112 ms 1072 KB Output is correct