답안 #881806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881806 2023-12-02T02:38:28 Z Requiem Nautilus (BOI19_nautilus) C++17
66 / 100
1000 ms 160084 KB
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define endl "\n"
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define pi 3.14159265359
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#define TASKNAME ""
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } 
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } 
using namespace std; 
typedef pair<int,int> ii; 
typedef pair<int,ii> iii; 
typedef vector<int> vi; 
const int MAXN = 5e2 + 9;
int n,m,k;
char c[MAXN][MAXN];
char dir[MAXN];
bitset<5002> dp[MAXN][MAXN];
main() 
{ 
    fast; 
   if (fopen(TASKNAME".inp","r")){
        freopen(TASKNAME".inp","r",stdin); 
        freopen(TASKNAME".out","w",stdout); 
   } 
   cin>>n>>m>>k;
   for(int i=1;i<=n;i++){
       for(int j=1;j<=m;j++){
           cin>>c[i][j];
           if (c[i][j] != '#') dp[i][j][0] = 1;
       }
   }
   for(int i=1;i<=k;i++){
       cin>>dir[i];
   }
   int i,j,t,ans=0;
   for(t=0;t<k;t++){
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                if (dp[i][j][t]){
                    if (j > 0 and dir[t+1] == 'W'){
                        if (c[i][j-1] == '.') dp[i][j-1][t+1] = 1;
                    }
                    if (j < m and dir[t+1] == 'E'){
                        if (c[i][j+1] == '.') dp[i][j+1][t+1] = 1;
                    }
                    if (i<n and dir[t+1] == 'S'){
                        if (c[i+1][j] == '.') dp[i+1][j][t+1] = 1;
                    }
                    if (i>1 and dir[t+1] == 'N'){
                        if (c[i-1][j] == '.') dp[i-1][j][t+1] = 1;
                    }
                    if (dir[t+1] == '?'){
                        if (j > 1 and c[i][j-1] == '.') dp[i][j-1][t+1] = 1;
                        if (j < m and c[i][j+1] == '.') dp[i][j+1][t+1] = 1;
                        if (i < n and c[i+1][j] == '.') dp[i+1][j][t+1] = 1;
                        if (i > 1 and c[i-1][j] == '.') dp[i-1][j][t+1] = 1;
                    }
                }
            }
        }
   }
   for(int i=1;i<=n;i++){
       for(int j=1;j<=m;j++){
          if (dp[i][j][k] == 1) ans++;
       }
   }
   cout<<ans<<endl;



} 

Compilation message

nautilus.cpp:15: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   15 | #pragma GCC optimization ("Ofast")
      | 
nautilus.cpp:16: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   16 | #pragma GCC optimization ("unroll-loops")
      | 
nautilus.cpp:29:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main()
      | ^~~~
nautilus.cpp: In function 'int main()':
nautilus.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen(TASKNAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen(TASKNAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 35164 KB Output is correct
2 Correct 6 ms 35384 KB Output is correct
3 Correct 6 ms 35160 KB Output is correct
4 Correct 5 ms 35304 KB Output is correct
5 Correct 5 ms 35164 KB Output is correct
6 Correct 3 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 35164 KB Output is correct
2 Correct 6 ms 35384 KB Output is correct
3 Correct 6 ms 35160 KB Output is correct
4 Correct 5 ms 35304 KB Output is correct
5 Correct 5 ms 35164 KB Output is correct
6 Correct 3 ms 8540 KB Output is correct
7 Correct 8 ms 35164 KB Output is correct
8 Correct 8 ms 35336 KB Output is correct
9 Correct 6 ms 35164 KB Output is correct
10 Correct 5 ms 35164 KB Output is correct
11 Correct 3 ms 6648 KB Output is correct
12 Correct 9 ms 35232 KB Output is correct
13 Correct 11 ms 35388 KB Output is correct
14 Correct 12 ms 35384 KB Output is correct
15 Correct 6 ms 35164 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 9 ms 35388 KB Output is correct
18 Correct 12 ms 35160 KB Output is correct
19 Correct 11 ms 35384 KB Output is correct
20 Correct 6 ms 35164 KB Output is correct
21 Correct 3 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 35164 KB Output is correct
2 Correct 6 ms 35384 KB Output is correct
3 Correct 6 ms 35160 KB Output is correct
4 Correct 5 ms 35304 KB Output is correct
5 Correct 5 ms 35164 KB Output is correct
6 Correct 3 ms 8540 KB Output is correct
7 Correct 8 ms 35164 KB Output is correct
8 Correct 8 ms 35336 KB Output is correct
9 Correct 6 ms 35164 KB Output is correct
10 Correct 5 ms 35164 KB Output is correct
11 Correct 3 ms 6648 KB Output is correct
12 Correct 9 ms 35232 KB Output is correct
13 Correct 11 ms 35388 KB Output is correct
14 Correct 12 ms 35384 KB Output is correct
15 Correct 6 ms 35164 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 9 ms 35388 KB Output is correct
18 Correct 12 ms 35160 KB Output is correct
19 Correct 11 ms 35384 KB Output is correct
20 Correct 6 ms 35164 KB Output is correct
21 Correct 3 ms 6492 KB Output is correct
22 Execution timed out 1020 ms 160084 KB Time limit exceeded
23 Halted 0 ms 0 KB -