# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
871702 | Acanikolic | Nautilus (BOI19_nautilus) | C++14 | 155 ms | 856 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 int long long
#define pb push_back
#define F first
#define S second
using namespace std;
const long long N = 510;
const long long mod = 1e9+7;
const long long inf = 1e18;
const int K = 510;
bitset<K>pravi[N],resenje[N];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int r,c,m;
cin >> r >> c >> m;
for(int i=1;i<=r;i++) {
for(int j=1;j<=c;j++) {
char x;
cin >> x;
pravi[i][j] = 0;
if(x == '.') pravi[i][j] = 1;
resenje[i][j] = 1;
}
resenje[i] = pravi[i] & resenje[i];
}
string s;
cin >> s;
for(int sta=0;sta<s.size();sta++) {
/* for(int i=1;i<=r;i++) {
if(s[sta] == 'N') {
resenje[i] = pravi[i] & resenje[i+1];
}else if(s[sta] == 'S') {
resenje[i] = pravi[i] & resenje[i-1];
}else if(s[sta] == 'W') {
resenje[i] = pravi[i] & (resenje[i] >> 1);
}else if(s[sta] == 'E') {
resenje[i] = pravi[i] & (resenje[i] << 1);
}else {
resenje[i] = pravi[i] & resenje[i+1];
resenje[i] |= pravi[i] & resenje[i-1];
resenje[i] |= pravi[i] & (resenje[i] << 1);
resenje[i] |= pravi[i] & (resenje[i] >> 1);
}
}*/
if(s[sta] == 'N') {
// gore
for(int i=1;i<=r;i++) resenje[i] = pravi[i] & resenje[i+1];
}else if(s[sta] == 'S') {
for(int i=r;i>=1;i--) resenje[i] = pravi[i] & resenje[i-1];
}else if(s[sta] == 'W') {
for(int i=1;i<=r;i++) resenje[i] = pravi[i] & (resenje[i] >> 1);
}else if(s[sta] == 'E') {
for(int i=1;i<=r;i++) resenje[i] = pravi[i] & (resenje[i] << 1);
}else {
bitset<K>tmp[N];
for(int i=1;i<=r;i++) {
tmp[i] |= pravi[i] & resenje[i+1];
tmp[i] |= pravi[i] & (resenje[i] >> 1);
tmp[i] |= pravi[i] & (resenje[i] << 1);
}
for(int i=r;i>=1;i--) tmp[i] |= pravi[i] & (resenje[i-1]);
for(int i=1;i<=r;i++) resenje[i] = tmp[i];
}
}
int res = 0;
for(int i=1;i<=r;i++) {
for(int j=1;j<=c;j++) res += resenje[i][j];
}
cout << res;
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... |