#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <limits.h>
#include <math.h>
#include <chrono>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define p2 pair<ll, ll>
#define p3 tuple<ll,ll,ll>
#define p4 vi
#define ip3 tuple<int,int,int>
#define ip4 tuple<int,int,int,int>
#define vp2 vector<p2>
#define vp3 vector<p3>
#define inf 2e9
#define linf 1e17
#define read(a) cin >> a
#define write(a) cout << (a) << "\n"
#define dread(type, a) type a; cin >> a
#define dread2(type, a, b) dread(type, a); dread(type, b)
#define dread3(type, a, b, c) dread2(type, a, b); dread(type, c)
#define dread4(type, a, b, c, d) dread3(type, a, b, c); dread(type, d)
#define dread5(type, a, b, c, d, e) dread4(type, a, b, c, d); dread(type, e)
#ifdef _DEBUG
#define deb __debugbreak();
#else
#define deb ;
#endif
#define rep(i, high) for (ll i = 0; i < high; i++)
#define repp(i, low, high) for (ll i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define per(i, high) for (ll i = high; i >= 0; i--)
#define readpush(type,vect) type temp; read(temp); vect.push_back(temp);
#define readvector(type, name, size) vector<type> name(size); rep(i,size) {dread(type,temp); name[i]=temp;}
#define readinsert(type,a) {type temp; read(temp); a.insert(temp);}
#define all(a) begin(a),end(a)
#define setcontains(set, x) (set.find(x) != set.end())
#define stringcontains(str, x) (str.find(x) != string::npos)
#define within(a, b, c, d) (a >= 0 && a < b && c >= 0 && c < d)
#define ceildiv(x,y) ((x + y - 1) / y)
#define fract(a) (a-floor(a))
#define sign(a) ((a>0) ? 1 : -1)
#define MW 500
auto Start = chrono::high_resolution_clock::now();
inline void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
ll w, h, m;
vector<vector<bool>> grid;
string instructions;
int main() {
//fast();
cin >> h >> w >> m;
grid.resize(w, vector<bool>(h));
for(int y = 0; y < h; y++) {
for(int x = 0; x < w; x++) {
char c;
cin >> c;
grid[x][y] = c == '#';
}
}
cin >> instructions;
vector<bitset<MW>> dp_state(h, bitset<500>()), free_pos(h, bitset<500>());
for(int y = 0; y < h; y++) {
for(int x = 0; x < w; x++) {
if(!grid[x][y]) free_pos[y].set(x, true);
}
dp_state[y] = free_pos[y];
}
for(auto iter = instructions.begin(); iter != instructions.end(); iter++) {
string dirs;
dirs += *iter;
if(dirs == "?") {
dirs = "ENWS";
}
vector<bitset<MW>> next_state(h, bitset<MW>());
for(char c : dirs) {
for(int y = 0; y < h; y++) {
switch (c)
{
case 'W':
next_state[y] |= (dp_state[y] >> 1);
break;
case 'E':
next_state[y] |= (dp_state[y] << 1);
break;
case 'N':
if(y + 1 < h) next_state[y] |= dp_state[y + 1];
break;
case 'S':
if(y > 0) next_state[y] |= dp_state[y - 1];
break;
}
}
}
for(int y = 0; y < h; y++) {
next_state[y] &= free_pos[y];
}
dp_state = next_state;
/*cout << "Instruction " << (*iter) << endl;
for(int y = 0; y < h; y++) {
for(int x = 0; x < w; x++) {
cout << (dp_state[y][x] ? "o" : (grid[x][y] ? "#" : "."));
}
cout << endl;
}*/
}
int ans = 0;
for(int y = 0; y < h; y++) {
ans += dp_state[y].count();
}
write(ans);
}
/*
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??
*/
Compilation message
nautilus.cpp:19: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
19 | #pragma GCC optimization ("O3")
|
nautilus.cpp:20: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
20 | #pragma GCC optimization ("unroll-loops")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
308 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
308 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
312 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
312 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
308 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
312 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
312 KB |
Output is correct |
20 |
Correct |
2 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
212 KB |
Output is correct |
22 |
Correct |
116 ms |
704 KB |
Output is correct |
23 |
Correct |
106 ms |
696 KB |
Output is correct |
24 |
Correct |
105 ms |
692 KB |
Output is correct |
25 |
Correct |
100 ms |
704 KB |
Output is correct |
26 |
Correct |
128 ms |
696 KB |
Output is correct |
27 |
Correct |
141 ms |
596 KB |
Output is correct |
28 |
Correct |
142 ms |
696 KB |
Output is correct |
29 |
Correct |
155 ms |
692 KB |
Output is correct |
30 |
Correct |
150 ms |
696 KB |
Output is correct |
31 |
Correct |
137 ms |
700 KB |
Output is correct |
32 |
Correct |
171 ms |
696 KB |
Output is correct |
33 |
Correct |
206 ms |
696 KB |
Output is correct |
34 |
Correct |
171 ms |
596 KB |
Output is correct |
35 |
Correct |
173 ms |
692 KB |
Output is correct |
36 |
Correct |
215 ms |
608 KB |
Output is correct |