이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define en cin.close();return 0;
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
int main()
{
fio
// ifstream cin("in.in");
int n, m, len;
cin >> n >> m >> len;
char gr[n+1][m+1];
vector<vector<bool> > can(n+1,vector<bool>(m+1)), can2 = can, st = can;
for(int i = 1;i<=n;i++)
for(int j = 1;j<=m;j++)
cin >> gr[i][j],
can[i][j]=(gr[i][j]=='.');
string str;
cin >> str;
for(auto x:str)
{
for(int i = 1;i<=n;i++)
{
for(int j = 1;j<=m;j++)
{
if(can[i][j])
{
if(x=='?')
{
for(int d = 0;d<4;d++)
{
int nwx = i+dx[d], nwy = j+dy[d];
if(nwx<1||nwx>n||nwy<1||nwy>m)
continue;
if(gr[nwx][nwy]=='.')
can2[nwx][nwy]=1;
}
}
else
{
int nwx = i, nwy = j;
if(x=='W')
nwy--;
else if(x=='N')
nwx--;
else if(x=='S')
nwx++;
else
nwy++;
if(nwx<1||nwx>n||nwy<1||nwy>m)
continue;
if(gr[nwx][nwy]=='.')
can2[nwx][nwy]=1;
}
}
}
}
swap(can,can2);
can2=st;
}
int res = 0;
for(int i = 1;i<=n;i++)
for(int j = 1;j<=m;j++)
res+=can[i][j];
cout << res;
// cin.close();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |