# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132078 | youssefbou62 | Nautilus (BOI19_nautilus) | C++14 | 266 ms | 158840 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.
#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab (int x ) { return (x>0?x:-x); }
const int N = 505 , M = 5005 ;
int R , C , m ;
bitset<N> dp[M][N] , a[N];
string seq ;
void direction(int& i, int& j , char c ){
if( c =='N'){
i-- ;
}else if( c =='S'){
i++;
}else if( c =='E'){
j++ ;
}else if( c =='W'){
j--;
}
}
bool valid (int i , int j ){
return ( i >= 0 && j >= 0 && i < R && j < C && a[i][j]!='#') ;
}
int main(){
scanf("%d%d%d\n",&R,&C,&m);
for(int i = 0 ; i < R ; i++ ){
for(int j = 0 ; j < C ; j++ ){
char c ;
scanf(" %c",&c);
a[i][j] = (c=='.') ;
}
}
for(int i = 0 ; i < R ; i++ ){
for(int j = 0 ; j < C ; j++ )
dp[0][i][j] = a[i][j];
}
cin >> seq ;
string dir = "NSWE";
for(int moves = 0 ; moves < m ; moves++){
for(int i=0 ; i < R ; i++ ){
char c = seq[moves] ;
if( (c=='N' || c=='?') && i ){
dp[moves+1][i-1] = (dp[moves][i]|dp[moves+1][i-1])&a[i-1];
}if(c=='S'|| c=='?'){
dp[moves+1][i+1] = (dp[moves][i]|dp[moves+1][i+1])&a[i+1];
}if(c=='E'|| c=='?'){
dp[moves+1][i] = (dp[moves+1][i]|(dp[moves][i]<<1))&a[i];
}if( c=='W' || c=='?'){
dp[moves+1][i] = (dp[moves+1][i]|(dp[moves][i]>>1))&a[i];
}
}
}
int ans = 0 ;
for(int i = 0 ; i < R ; i++ )ans += dp[m][i].count();
cout << ans << endl ;
}
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... |