# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
131679 | youssefbou62 | Nautilus (BOI19_nautilus) | C++14 | 1073 ms | 2808 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>
using namespace std;
#pragma GCC optimize ("O3")
#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 , dp[2][N][N];
string seq ;
char a[N][N] ;
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(){
int m ;
scanf("%d%d%d\n",&R,&C,&m);
for(int i = 0 ; i < R ; i++ ){
for(int j = 0 ; j < C ; j++ ){
scanf(" %c",a[i]+j) ;
}
}
cin >> seq ;
for(int i = 0 ; i < R ; i++ ){
for(int j = 0 ; j < C ;j++)
dp[0][i][j] = 1 ;
}
// memset(dp[0],1,sizeof dp[0]);
string dir = "NSWE";
for(int moves = 0 ; moves < m ; moves++ ){
for(int i = 0 ; i < R ; i++ ){
for(int j = 0 ; j < C ; j++ ){
int y= j , x = i ;
if( a[i][j] == '#')continue ;
for(char c : dir ){
if( seq[moves] == '?' || c==seq[moves] ){
direction(x,y,c);
if( valid ( x , y ) ){
dp[1][x][y] |= dp[0][i][j];
}
x = i ;
y = j ;
}
}
}
}
for(int i = 0 ; i < R ; i++ ){
for(int j = 0 ; j < C ; j++ ){
dp[0][i][j] =dp[1][i][j];
dp[1][i][j] =0 ;
}
}
}
// for(int mm =0 ; mm < m ; mm++ ){
// cout << mm << endl;
// for(int i = 0 ; i < R ; i++ ){
// for(int j = 0 ; j < C ; j++ )cout << dp[m][i][j]<< " ";
// cout << endl;
// }
// cout << endl;
// }
int ans = 0 ;
for(int i = 0 ; i < R ; i++ )for(int j = 0 ; j < C ; j++ )ans += dp[0][i][j] ;
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... |