#include <bits/stdc++.h>
using namespace std;
const int maxn = 510;
int n, m, l, used[maxn][maxn];
int dir(char c)
{
if (c == 'N')
return 0;
if (c == 'E')
return 1;
if (c == 'S')
return 2;
if (c == 'W')
return 3;
return -1;
}
char c[maxn][maxn];
int us[maxn][maxn];
pair < int, int > nb[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
void solve()
{
cin >> n >> m >> l;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
{
cin >> c[i][j];
if (c[i][j] == '#')
used[i][j] = 1;
}
for (int i = 0; i <= n + 1; i ++)
used[i][0] = used[i][m + 1] = 1;
for (int i = 0; i <= m + 1; i ++)
used[0][i] = used[n + 1][i] = 1;
vector < pair < int, int > > v;
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
if (used[i][j] == 0)
v.push_back({i, j});
for (int i = 1; i <= l; i ++)
{
for (int j = 1; j <= n; j ++)
for (int p = 1; p <= m; p ++)
us[j][p] = 0;
char c;
cin >> c;
vector < pair < int, int > > new_v;
for (int d = 0; d < 4; d ++)
{
if (dir(c) == d || dir(c) == -1)
{
for (int j = 0; j < v.size(); j ++)
{
pair < int, int > neib = v[j];
neib.first = neib.first + nb[d].first;
neib.second = neib.second + nb[d].second;
if (used[neib.first][neib.second])
continue;
us[neib.first][neib.second] = 1;
}
}
}
/** for (int j = 1; j <= n; j ++, cout << endl)
for (int p = 1; p <= m; p ++)
cout << us[j][p];
cout << "-----------------" << endl;*/
for (int j = 1; j <= n; j ++)
for (int p = 1; p <= m; p ++)
if (us[j][p])
new_v.push_back({j, p});
v = new_v;
}
cout << v.size() << endl;;
}
int main()
{
solve();
return 0;
}
Compilation message
nautilus.cpp: In function 'void solve()':
nautilus.cpp:60:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int j = 0; j < v.size(); j ++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1080 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
2 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
724 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1080 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
2 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
724 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
25 ms |
1080 KB |
Output is correct |
8 |
Correct |
7 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
824 KB |
Output is correct |
10 |
Correct |
3 ms |
832 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
31 ms |
1084 KB |
Output is correct |
13 |
Correct |
26 ms |
1072 KB |
Output is correct |
14 |
Correct |
19 ms |
944 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
29 ms |
1076 KB |
Output is correct |
18 |
Correct |
33 ms |
956 KB |
Output is correct |
19 |
Correct |
18 ms |
880 KB |
Output is correct |
20 |
Correct |
8 ms |
724 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1080 KB |
Output is correct |
2 |
Correct |
3 ms |
852 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
2 ms |
852 KB |
Output is correct |
5 |
Correct |
3 ms |
724 KB |
Output is correct |
6 |
Correct |
2 ms |
724 KB |
Output is correct |
7 |
Correct |
25 ms |
1080 KB |
Output is correct |
8 |
Correct |
7 ms |
852 KB |
Output is correct |
9 |
Correct |
4 ms |
824 KB |
Output is correct |
10 |
Correct |
3 ms |
832 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
31 ms |
1084 KB |
Output is correct |
13 |
Correct |
26 ms |
1072 KB |
Output is correct |
14 |
Correct |
19 ms |
944 KB |
Output is correct |
15 |
Correct |
3 ms |
724 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
29 ms |
1076 KB |
Output is correct |
18 |
Correct |
33 ms |
956 KB |
Output is correct |
19 |
Correct |
18 ms |
880 KB |
Output is correct |
20 |
Correct |
8 ms |
724 KB |
Output is correct |
21 |
Correct |
2 ms |
724 KB |
Output is correct |
22 |
Execution timed out |
1082 ms |
8812 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |