이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 505
int arr[N][N], s[5005], done[N][N];
int32_t main()
{
fastio();
pii dir[] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
map<char, int> val;
val['N'] = 0, val['E'] = 1, val['S'] = 2, val['W'] = 3, val['?'] = 4;
int r, c, m;
cin>>r>>c>>m;
vector<pii> curr;
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= c; j++)
{
char tmp;
cin>>tmp;
if (tmp == '.') arr[i][j] = 1, curr.pb({i, j});
}
}
for (int i = 1; i <= m; i++)
{
char tmp;
cin>>tmp;
s[i] = val[tmp];
}
for (int i = 1; i <= m; i++)
{
//cout<<curr.size()<<endl;
vector<pii> tmp;
for (auto j : curr)
{
int x = j.st, y = j.nd;
int k = s[i];
if (k == 4)
{
for (auto l : dir)
{
int a = x + l.st, b = y + l.nd;
if (arr[a][b] == 1 && done[a][b] < i + 1)
{
done[a][b] = i + 1;
tmp.pb({a, b});
}
}
}
else
{
pii l = dir[k];
int a = x + l.st, b = y + l.nd;
if (arr[a][b] == 1 && done[a][b] < i + 1)
{
done[a][b] = i + 1;
tmp.pb({a, b});
}
}
}
curr = tmp;
}
cout<<curr.size()<<endl;
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<"seconds\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |