#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const double PI = 4 * atan(1);
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void io(string taskname){
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
// freopen(FOUT, "w", stdout);
fast_io();
}
const int MAX = 2505;
int grid[MAX][MAX];
int use[MAX][MAX];
int r, c, m;
inline int valid(int x, int y){
if(0<= x && x<r &&0<= y && y<c && grid[x][y] == 0 && use[x][y] == 0) {
use[x][y] = 1;
return 1;
}
return 0;
}
///0 up 1 right 2 down 3 left
int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
vi v;
int main(){
fast_io();
cin >> r >> c >> m;
string temporary;
getline(cin, temporary);
f0r(i, r){
string line;
getline(cin, line);
f0r(j, c){
if(line[j] == '#') grid[i][j] = 1;
}
}
string line;
getline(cin, line);
f0r(i, m){
if(line[i] == 'N'){
v.eb(0);
}
else if(line[i] == 'E'){
v.eb(1);
}
else if (line[i] == 'S'){
v.eb(2);
}
else if(line[i] == 'W'){
v.eb(3);
}
else{
v.eb(-1);
}
}
vpi from;
vpi to;
f0r(i, r){
f0r(j, c){
if(grid[i][j] == 0) from.eb(mp(i, j));
}
}
f0r(i, m){
to.clear();
for(auto x: from){
if(v[i] != -1){
pii nxt = x;
nxt.f += dir[v[i]][0];
nxt.s += dir[v[i]][1];
if(valid(nxt.f, nxt.s)){
to.eb(nxt);
}
}
else{
f0r(d, 4){
pii nxt = x;
nxt.f += dir[d][0];
nxt.s += dir[d][1];
if(valid(nxt.f, nxt.s)){
to.eb(nxt);
}
}
}
}
for(auto x: to){
use[x.f][x.s] = 0;
}
swap(to, from);
}
cout << sz(from) << endl;
return 0;
}
Compilation message
nautilus.cpp:1: warning: ignoring #pragma comment [-Wunknown-pragmas]
1 | #pragma comment(linker, "/stack:200000000")
|
nautilus.cpp: In function 'void io(std::string)':
nautilus.cpp:53:17: warning: unused variable 'FOUT' [-Wunused-variable]
53 | const char* FOUT = fout.c_str();
| ^~~~
nautilus.cpp:54:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
54 | freopen(FIN, "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1132 KB |
Output is correct |
2 |
Correct |
2 ms |
1388 KB |
Output is correct |
3 |
Correct |
2 ms |
1388 KB |
Output is correct |
4 |
Correct |
1 ms |
1388 KB |
Output is correct |
5 |
Correct |
1 ms |
1260 KB |
Output is correct |
6 |
Correct |
1 ms |
876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1132 KB |
Output is correct |
2 |
Correct |
2 ms |
1388 KB |
Output is correct |
3 |
Correct |
2 ms |
1388 KB |
Output is correct |
4 |
Correct |
1 ms |
1388 KB |
Output is correct |
5 |
Correct |
1 ms |
1260 KB |
Output is correct |
6 |
Correct |
1 ms |
876 KB |
Output is correct |
7 |
Correct |
13 ms |
1132 KB |
Output is correct |
8 |
Correct |
7 ms |
1516 KB |
Output is correct |
9 |
Correct |
2 ms |
1260 KB |
Output is correct |
10 |
Correct |
2 ms |
1260 KB |
Output is correct |
11 |
Correct |
1 ms |
896 KB |
Output is correct |
12 |
Correct |
18 ms |
1132 KB |
Output is correct |
13 |
Correct |
22 ms |
1388 KB |
Output is correct |
14 |
Correct |
18 ms |
1388 KB |
Output is correct |
15 |
Correct |
2 ms |
1260 KB |
Output is correct |
16 |
Correct |
1 ms |
876 KB |
Output is correct |
17 |
Correct |
19 ms |
1132 KB |
Output is correct |
18 |
Correct |
26 ms |
1388 KB |
Output is correct |
19 |
Correct |
14 ms |
1260 KB |
Output is correct |
20 |
Correct |
5 ms |
1260 KB |
Output is correct |
21 |
Correct |
1 ms |
1004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1132 KB |
Output is correct |
2 |
Correct |
2 ms |
1388 KB |
Output is correct |
3 |
Correct |
2 ms |
1388 KB |
Output is correct |
4 |
Correct |
1 ms |
1388 KB |
Output is correct |
5 |
Correct |
1 ms |
1260 KB |
Output is correct |
6 |
Correct |
1 ms |
876 KB |
Output is correct |
7 |
Correct |
13 ms |
1132 KB |
Output is correct |
8 |
Correct |
7 ms |
1516 KB |
Output is correct |
9 |
Correct |
2 ms |
1260 KB |
Output is correct |
10 |
Correct |
2 ms |
1260 KB |
Output is correct |
11 |
Correct |
1 ms |
896 KB |
Output is correct |
12 |
Correct |
18 ms |
1132 KB |
Output is correct |
13 |
Correct |
22 ms |
1388 KB |
Output is correct |
14 |
Correct |
18 ms |
1388 KB |
Output is correct |
15 |
Correct |
2 ms |
1260 KB |
Output is correct |
16 |
Correct |
1 ms |
876 KB |
Output is correct |
17 |
Correct |
19 ms |
1132 KB |
Output is correct |
18 |
Correct |
26 ms |
1388 KB |
Output is correct |
19 |
Correct |
14 ms |
1260 KB |
Output is correct |
20 |
Correct |
5 ms |
1260 KB |
Output is correct |
21 |
Correct |
1 ms |
1004 KB |
Output is correct |
22 |
Execution timed out |
1096 ms |
7804 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |