# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
955637 | n3rm1n | Nautilus (BOI19_nautilus) | C++17 | 1064 ms | 604 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int MAXN = 505, MAXCELL = 3e5+10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int n, m, t;
int a[MAXN][MAXN];
string operations;
bitset < MAXCELL > fr;
void read()
{
cin >> n >> m >> t;
char s;
for (int i = 1; i <= n; ++ i)
{
for (int j = 1; j <= m; ++ j)
{
cin >> s;
if(s == '#')
{
a[i][j] = 1;
}
else
{
fr[(i-1) * m + j] = 1;
// cout << i << " " << j << " is coded as " << (i-1) * m + j << endl;
}
}
}
cin >> operations;
//cout << fr.count() << endl;
}
bitset < MAXCELL > ans, last, newmove;
void go_south()
{
newmove = (newmove | (last << m));
newmove = (newmove & fr);
}
void go_north()
{
newmove = (newmove | (last >> m));
newmove = (newmove & fr);
}
void go_east()
{
newmove = (newmove | (last << 1));
newmove = (newmove & fr);
}
void go_west()
{
newmove = (newmove | (last >> 1));
newmove = (newmove & fr);
}
void solve_for(int start)
{
last = (last ^ last);
last[start] = 1;
last = (last & fr);
for (int i = 0; i < operations.size(); ++ i)
{
newmove = (newmove ^ newmove);
if(operations[i] == '?' || operations[i] == 'N')go_north();
if(operations[i] == '?' || operations[i] == 'S')go_south();
if(operations[i] == '?' || operations[i] == 'E')go_east();
if(operations[i] == '?' || operations[i] == 'W')go_west();
last = newmove;
}
last = (last & fr);
ans = (ans | last);
}
void solve()
{
for (int start = 1; start <= n*m; ++ start)
{
solve_for(start);
}
cout << ans.count() << endl;
/*for (int i = 1; i <= n; ++ i)
{
for (int j = 1; j <= m; ++ j)
cout << ans[(i-1) * m + j] << " ";
cout << endl;
}*/
}
int main()
{
speed();
read();
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |